The most useful Docker commands for DBA

In my latest blog post, I described How to start SQL Server Docker container in few simple steps. Since then I was playing a bit with Docker and now I want to share with you a list of the most useful Docker commands.

Check Docker version

You can check Docker version very easily using this command:

docker version

Example output:

Docker version

List downloaded images

To display a list of already downloaded (pulled) images use one of these commands:

docker image ls
docker images

Example output:

Docker images

Search for new image

You can use https://hub.docker.com/ to search for new images, but you can do this also from command line.

docker search [searchphrase]

Example output:

Docker search

Pull the image

To pull (download) the image you need to run this command:

docker pull <imagename>

Example output:

Docker pull

Run new container

To run new container use this command:

docker run <imagename>

Example output:

Docker run hello-world

Sometimes you need to provide additional parameters.

docker run --name <CONATINER_NAME> -d -p 1433:1433 -e sa_password=<SA_PASSWORD> -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer
Docker run mssql
List containers

To list running containers use:

docker ps

Docker ps

To list all created containers use:

docker ps -a

Docker ps -a

Stop container

To stop container:

docker stop <container ID>

To stop all running containers:

docker stop $(docker ps -a -q)
Start container

To start container:

docker start <container ID>

To start all containers

docker start $(docker ps -a -q)
Remove container

To remove container:

docker rm <conatiner ID>

To remove all containers:

docker rm $(docker ps -a -q)
Remove image

To remove image:

docker rmi <image ID>

Docker rmi

Copy files

To copy files between host and container use cp command:

docker cp <Container ID>:<Container path> <host path>
docker cp <host path> <Container ID>:<Container path>

 

I hope you find this list useful. Thanks for reading!

-Marek

Share it:
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

One thought on “The most useful Docker commands for DBA”

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close