Dockerlab 102 Interacting with Docker Container
Step 0 : Create docker hub account. https://hub.docker.com
Step 1 : Open Play with Docker or login in below with your docker hub account.
Step 2 : Click on start
Step 3 : It will start a 4 hr session, click on + ADD NEW INSTANCE
Step 4 : Click in terminal and press enter.
Step 5 :
docker pull ubuntu
docker pull ubuntu:18.04
docker pull ubuntu:20.10
docker pull ubuntu:16.04
docker pull alpine
docker pull alpine:3.12.0
docker pull alpine:3.11.6
docker pull alpine:3.10
pull command fetches image from docker registry and saves it in your system.
In this case docker registry is docker hub, we will practice changing registry in future labs.
Step 6 : docker images
docker images command is used to check images on local system
Step 7 : docker images -a
-a will show all images
Step 8 : docker images ubuntu
this command will list all ubuntu images with different tags
Step 9 : docker image ls
list all images on local system
Step 10 : docker container run alpine ls -l
docker container run will start a container and run command in new container
This will run ls -l command in container and print output. Container will exit after running this command.
Step 11 : docker container run alpine echo "hello from alpine"
This will run echo command and container will shutdown after running this command.
Step 12 : docker container run alpine /bin/sh
This will do nothing as container will run command and exit
Step 13 : docker container run -it alpine /bin/ash
echo "hello world" > hello.txt
This will take you inside new container, you can run any alpine supported command and exit once you are done
Step 14 : docker container ls
This command will display all running containers
Step 15 : docker container ls -a
-a will display all containers with all status
All containers have isolated file system
Step 16 : docker container start <container ID>
you can start an exited container, you can use just first 4 digit of container id, full id is not required.
Step 17: docker container exec <container ID> ls
File we created in earlier will be there even if container exit.
You will loose file if container is removed more on that in future labs.