Nutshell

Pull Image

docker pull debian

Create container from image

docker run debian # The container will get a random name.
docker run debian --name "my-debian" # recommended

Start a container and mount Apache document root to a local folder in your workstation:

docker run --name "my-debian" -it --mount type=bind,source=/work/my-projects,target=/var/www/html debian

Start/Stop container

docker start my-debian
docker stop my-debian

Connect container

docker exec -it my-debian /bin/bash

List running containers

docker ps

List all containers

docker ps -a

List images

docker image ls

Delete container

docker rm my-debian

Delete image

docker rmi debian

Save container as an image

docker commit my-container username/my-image:bkp1
# then
docker save username/my-image:bkp1 > my-image.tar

Load an image from backup

docker load < my-image.tar

Push image

docker commit [contauner_ID] user/image

Build an image

You can create custom images using docker build. For example, you can start from a base image (eg Debian) and the install custom software according to your needs (php, Apache, MySQL or whatever).

docker build

Transfer files

From local file system to running container:

docker cp /store/test.conf my-container:/etc/test.conf 

From running container to local file system:

docker cp my-container:/etc/test.conf /store/test.conf

Docker info

docker info

Docker inspect

Use docker inspect to get information for a specific docker object (eg image, container, network, etc)

docker inspect my-container

Last updated