Installing Docker
1 |
# sudo apt install docker.io |
setup docker user as root to eliminate sudo
1 2 3 |
# sudo usermod -aG docker ${USER} # su - ${USER} # id -nG |
Searching for docker images
1 |
# docker search ubuntu |
pull image
1 |
# docker pull ubuntu |
run the image
1 |
# docker run -it ubuntu |
List images
1 |
# docker images |
delete image
1 |
# docker image rm [name] |
Containers
Running instance of an image
See all running containers
1 |
# docker container ls |
delete container
1 |
# docker container rm [name] |
Task
Create a new directory
Create a simple scipt – simple.py:
1 2 3 4 5 6 7 8 9 10 |
<span style="font-size: 14pt;">import time i=0 f=open('mylog.log','w') while True: f.write("simple:" + str(i) + "\n") f.flush() i+=1 time.sleep(2) </span> |
Create a simple file – Dockerfile
1 2 3 4 5 |
<span style="font-size: 14pt;">FROM python:3.7-slim COPY . /app WORKDIR /app CMD python ./simple.py </span> |
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