Basic Docker Commands

Petr Kostelanský | 22 September 2021
A few basic commands to easily manage docker images and containers.

 

Create docker image from Dockerfile (docker build):

docker build -t my-app-image:1.1 -f Dockerfile .

-t (--tag) name and optionally tag (image-name:tag)
-f (--file) name of the Dockerfile (default is Dockerfile)

Create a container from the image (docker create):

docker create --name my-app-container my-app-image:1.1

List all containers:

docker ps -a

Start container:

docker start my-app-container

Stop container:

docker start my-app-container

Run command in a new container (or just create and start a container by one command; docker run):

docker run -p 8080:80 --name my-app-container  my-app-image:1.2

 

I recommend you to use Docker Desktop to play with Docker containers locally.

 

Loading ads...