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

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:

2022-03-30 08_54_13-cmd

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

2022-03-30 08_54_29-cmd

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

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

2022-03-30 08_58_47-cmd

And the names:

2022-03-30 08_58_51-cmd

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 way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , . Bookmark the permalink.