:: krowemoh

Friday | 27 DEC 2024
Posts Links Other About Now

previous
next

Docker Cheatsheet

2023-09-29
cheatsheet

Helpful docker commands.

An Image is a base that when you run will create a container that matches the image.

Add a user to have access to docker:

usermod -a -G docker username

Get an image:

docker pull debian

List docker containers:

docker ps -a

Run an image (creates a running container):

docker run -it debian

Start a container:

docker start name_of_container

Connect to a container:

docker attach name_of_container

Attach a volume to an image and expose a port:

docker run -it -v /local/path/folder:/root/app/folder -p 7203:7203 image-name

Copy a file from the host system to the container:

docker cp test.py container_name:/root/test.py

Remove a container:

docker rm container-name

Save the current configuration of a container, the commit number comes from thentainer id from the listing:

docker commit 630646a22221 new-image-name

Remove container that aren't running:

docker containers prune

Save an image to load elsewhere:

docker save -o /path/to/saved.tar image-name

Load the image:

docker load -i /path/to/saved.tar