1

Setting the Container Name–#SQLNewBlogger

 2 years ago
source link: https://voiceofthedba.com/2022/04/11/setting-the-container-name-sqlnewblogger/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Setting the Container Name–#SQLNewBlogger

I had started a Stairway series on containers (which I need to get back to), and I got a question. How do we set the name of a container?

If I just start a new container with a generic, minimal command, I get a random name. As an example, I’d run something like this:

docker run -p 51433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Demo12#4" -v C:\Docker\SQL:/sql -d mcr.microsoft.com/mssql/server:2019-latest

Now if I look at the list of containers, what I see is this container running under the name, “”. Not a huge problem, but when you have a lot of containers, this isn’t ideal. If you look below, this container is the first one in my list:

However, the first name is listed as crazy_mirzakhani, not something I chose. I broke the image because it’s so wide.

Let me now start a new container, same image, but with a name. I do this by adding the –name parameter with a value.

docker run --name dockernamedemo -p 52433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Demo12#4" -v C:\Docker\SQL:/sql -d mcr.microsoft.com/mssql/server:2019-latest

Now if I look at the container list, I see this:

And the names:

This is useful to help me keep track of the containers I’ve got running.

This doesn’t address naming standards, which I might look at as something else that can be complex. I tend to use SQLxxxx where xxxx is the version. If I need multiple ones, I tend to use SQL2019, SQL2019_2, SQL2019_3, etc. Not the best way to do things, but since I match up ports, this is easy for connections. SQL2019 is 51433. SQL2019_2 is 52433, etc.

SQL New Blogger

When I saw the question, it was a couple minutes to find a reference and give an answer. I decided to take 10 more minutes and just write this post, publishing a short reference on how to name a container.

I added a short bit at the end on naming standards, which might be a good thing for you to write on as well.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK