Build a dockerfile:
docker build -t <name> .
List the available images:
Run an image:
docker run <image_name>:<tag>
If you want to run it in the background use
docker run elastalert:latest -d
If you want to publish a containers ports to the host use
docker run elastalert:latest -d -p 3030:3030 -p 3333:3333 --net="host"
If you want to bind a volume use
docker run elastalert:latest -d -p 3030:3030 -v $HOME/myContainer/configDir:/myImage/configDir
--name to assign a name to the container
More info on the docker run reference
View all running and non-running containers:
docker ps -a
Remove an image:
docker rm <name>
Get the reason why a docker container exited:
docker logs <container-id>
Inspect the container:
docker inspect <container-id>
Ensure a container is removed when it exits or stops, use
docker run --rm -d --network host --name my_nginx nginx
You got Images and Containers, and you need to know what state you are at: * Does the docker image exist? * Does the docker container exist? * Is the docker container running?
Then you will snow how your command should look. if we are talking containers your command will look like:
docker container <command>
These are container commands:
create— Create a container from an image.
start— Start an existing container.
run— Create a new container and start it.
ls— List running containers.
inspect— See lots of info about a container.
logs— Print logs.
stop— Gracefully stop running container.
kill—Stop main process in container abruptly.
rm— Delete a stopped container.
If we are dealing with images:
docker image <command>
These are image commands:
build— Build an image.
push— Push an image to a remote registry.
ls— List images.
history— See intermediate image info.
inspect— See lots of info about an image, including the layers.
rm— Delete an image.
docker version— List info about your Docker Client and Server versions.
docker login— Log in to a Docker registry.
docker system prune— Delete all unused containers, unused networks, and dangling images.
Create a container from an image
docker container create my_repo/my_image:my_tag
You can use
-a for attach (for
docker container create -a STDIN my_image
Start an existing container
docker container start my_container
A container can be reffered to by its id or name
Run combines both create and start:
docker container run my_image
--interactive- Keep STDIN open even if unattached
--tty- Allocates a pseudo terminal that connects your terminal with the container’s STDIN and STDOUT
--port- The port is the interface with the outside world.
1000:8000maps the docker port
1000on your machine / host. Eg. go to
localhost:1000on your host
--rm- automatically remove container when it stops running
--detach- Run the container in the background as a daemon
List all containers and sizes:
docker container ls -a -s
Inspect a container:
docker container inspect my_container
Print a containers log:
docker container logs my_container
Stop a running container:
docker container stop my_container
Stop a running container immediately (abruptly):
docker container kill my_container
Kill all running containers:
docker container kill $(docker ps -q)
Delete one or more containers:
docker container rm my_container
Build a docker image from a dockerfile located at a specific path:
docker image build -t my_repo/my_image:my_tag .
Pushing an image to a registry
docker image push my_repo/my_image:my_tag
List images and sizes
docker image ls
View the history of an image:
docker image history my_image
Show details and layers of your image:
docker image inspect my_image
Remove an image
docker image rm my_image
Delete unused containers, unused networks and dangling images
docker system prune