Docker Basics


Create a Container

docker create <image name> 

Obs: Returns the container id.

Start a Container

docker start - a <container id> 

Obs: The "-a" shows the output of the container in the terminal.

Creating And Running a Container from an Image

docker run <image name> <command>

Obs: Once you created a container with a command, you can not override it.

List Running Containers

docker ps

List All Containers Ever Created

docker ps --all

Restarting Stopped Containers

docker start -a <container id> 

Removing Stopped Containers

docker system prune

Retrieving Log Outputs

docker logs <container id>

This will not re-running or re-starting the container, but will retrieve all the information that has been emitted from it.

Stopping Container

docker stop <container id>

docker Kill <container id>

When using stop, docker gives enough time for the container to shut down properly. (After 10 seconds, it will emit the kill command if the container doesn't stop). The kill command, stop it immediately.

Execute an additional command in a container

docker exec -it <container id> <command>

Run this command while the container is running.

Open a shell in the context of a running container

docker exec -it <container id> sh

Tip: To exit try ctr+c, if it doesn't work, try ctr+d or type "exit"

Its also possible to use:

 docker run it <image name> sh

This will run the shell before the default container's commands

Tagging a image

 docker build -t <your docker id> / <project name> : version (or latest) <project directory>

Docker Compose


docker-compose up -d --build

Launch Containers in the background

docker-compose up -d

Stop Containers

docker-compose down

Check Container Status

docker-compose ps

You'll only receive email when they publish something new.

More from Teo Oliver