docker run: starts container with given image.
docker ps: displays list of available containers.
docker stop: stops the container.
docker rm: removes stopped container.
docker images: displays list of images.
docker rmi: removes unused images.
docker build: builds image from dockerfile.
docker-compose up: launches application built with multiple containers.
docker exec: launches command in running container.
docker logs: displays logs from running container.
docker inspect: shows info about container / image.
Exercises:
-
Pull docker image
alpine
and build Dockerfile which would copy local item .txt to container. Set /bin/sh the default action for container.Solution
FROM alpine WORKDIR /app COPY file.txt . CMD ["/bin/sh"]
Then it would use bash command in Dockerfile to replace all characters A with B and would save it to file2.txt.
#Command to use: sed "s/A/B/g" file.txt | tee file2.txt
Run newly created container with
docker run -it
command. Use commanddocker ps
to find latestcontainer ID
of container using your image.Solution
docker run -it ImageID
In seperated terminal try to access logs from this container. Use
docker logs -f ContainerID
command.Execute bash command to see file2.txt content on running container to see output. Try to make it in the same terminal window where you used
docker run -it
and try to executedocker exec containerId cat file2.txt
. Try to explain the observation.Solution
`docker logs` shows you only output from CMD/Entrypoint of container and skipping any other output. It is because we are getting information only from one single shell.
TODO - DOCKER MULTI STAGE