Docker Exercise 3
Docker Exercise 3
Get to know the following commands. Play around with your Docker environment and try out all the commands.
Tag an image
Create an image and give a name to it. Name is a group of images and tag further specifies the application.
docker build -t name:tag .
For example:
docker build -t helloworlddocker build -t helloworld:latestdocker build -t helloworld:v3
The tag latest will be added as a default if you don’t specify a tag yourself.
Give a container a name
docker run -p 3000:80 -d --rm --name helloworldcontainer helloworld
-p … Port forwarding -d … detached —rm remove the container after it is stopped —name give the container a name
Managing images and containers
# list running containersdocker ps
# list running and stopped containersdocker ps -a
# stop a running containerdocker stop id_or_name
# remove a stopped containerdocker rm id_or_name
# remove an imagedocker rmi id
# remove all unused images (images where no container is running)docker image prune
# automatically remove a running container when it exitsdocker run --rm some_image
# see information about imagedocker image inspect id