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:
List downloaded images
To display a list of already downloaded (pulled) images use one of these commands:
docker image ls docker images
Example output:
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:
Pull the image
To pull (download) the image you need to run this command:
docker pull <imagename>
Example output:
Run new container
To run new container use this command:
docker run <imagename>
Example output:
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
List containers
To list running containers use:
docker ps
To list all created containers use:
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>
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:
One thought on “The most useful Docker commands for DBA”