Lab – Docker

Installing Docker

# sudo apt install docker.io

setup docker user as root to eliminate sudo

# sudo usermod -aG docker ${USER}
# su - ${USER}
# id -nG

Searching for docker images

# docker search ubuntu

pull image

# docker pull ubuntu

run the image

# docker run -it ubuntu

List images

# docker images

delete image

# docker image rm [name]

Containers

Running instance of an image

See all running containers

# docker container ls

 

delete container

# docker container rm [name]

 

Task

Create a new directory

Create a simple scipt – simple.py:

import time

i=0
f=open('mylog.log','w')
while True:
	f.write("simple:" + str(i) + "\n")
	f.flush()
	i+=1
	time.sleep(2)

Create a simple file – Dockerfile

FROM python:3.7-slim
COPY . /app
WORKDIR /app
CMD python ./simple.py

Build the docker image:

 

            docker build ./ -t simple:v1.0

 

list all images:

 

            docker image ls

 

run the image in a container:

 

            docker run simple:v1.0

 

to see the generated file, first find the container id:

 

docker container ls

 

then, print the file content:

 

docker container exec c86ba06875ea cat mylog.log

 

stop the container:

 

docker stop [id]

 

save the container to a file:

 

docker save simple:v1.0 > simp.tar

 

to load it in another machine:

 

            docker load < simp.tar