Table of Contents
Docker stuff
This assumes you are running Docker on Linux, if anybody actually wants to use windows, see here:- Docker on windows
Build container from Dockerfile
This adds a Repository and tag, note the .
at the end is required, it means look in this directory for the Dockerfile:-
# docker build -t gss/sai:apache2-wsgi . # docker build -t friendlyello --tag=friendlyhello . # docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE gss/sai apache2-wsgi 324aaa642a04 10 seconds ago 300MB
Export image to file
# docker save 601fc78e12f7 > ../wsgi-apache2-v2.tar
Import image to Docker
root@ubuntu20:~# docker load < wsgi-apache2.tar ee8944188361: Loading layer [===========================================>] 7.642MB/7.642MB de7495326c39: Loading layer [===========================================>] 20.48kB/20.48kB 927524753f9c: Loading layer [===========================================>] 20.48kB/20.48kB 378475152b3a: Loading layer [===========================================>] 20.48kB/20.48kB 28d8ea9c3303: Loading layer [===========================================>] 20.99kB/20.99kB bd7760437189: Loading layer [===========================================>] 2.56kB/2.56kB Loaded image ID: sha256:5326892bf34d703dccd6d2281baf7dd482d813ccaf4f322639ddc89b2c439700 root@ubuntu20:~# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE gss/sai apache2-wsgi 324aaa642a04 11 days ago 300MB
Running container
-p 8080:80 | Map TCP port 80 in the container to port 8080 on the Docker host. |
-p 192.168.1.100:8080:80 | Map TCP port 80 in the container to port 8080 on the Docker host for connections to host IP 192.168.1.100 |
# docker run -d -p 80:80 324aaa642a04 e0733a7c4fb9bded46e5c0f4f4abd9919ff58a61b311bda4265acfe7dc534e32 # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e0733a7c4fb9 324aaa642a04 "httpd -D FOREGROUND…" 10 seconds ago Up 8 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp amazing_swartz
Note docker ps -a
shows a history of containers.
docker logs <container_name>
Docker exec
Run bash shell in container
# docker exec -it e0733a7c4fb9 /bin/bash
$ docker run -it python-docker-test
docker stop 1bd7ed055412
docker info
docker inspect <container id>
docker image rm
$ docker build –tag python-docker-test .
$ docker run --name andrew1 -d -p 4000:80 bae2beae2108 d37e2100cbf0fc61b9cd21ceb0734e19b501c3888fa4bb1411f99a5c2d6beb0a $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d37e2100cbf0 bae2beae2108 "python app.py" 4 seconds ago Up 3 seconds 0.0.0.0:4000->80/tcp andrew1 $
Start and stop containers, background to daemon mode with -d
.
$ docker-compose up -d Recreating 2ndtest_redis_1 ... done Recreating 2ndtest_web_1 ... done $ $ docker-compose down Stopping 2ndtest_web_1 ... done Stopping 2ndtest_redis_1 ... done Removing 2ndtest_web_1 ... done Removing 2ndtest_redis_1 ... done Removing network 2ndtest_default $
docker-compose.yml version: '3' services: web: build: . image: flask_web ports: - "5000:5000" links: - redis networks: - flask_app environment: - REDIS_URL=redis://cache restart: unless-stopped redis: image: "redis:alpine" container_name: cache networks: - flask_app restart: unless-stopped networks: flask_app: driver: bridge
Run flask bound to external interface:- ### python3 -m flask run –host=0.0.0.0
Or:- flask –app sample –debug run
Bind mount persistent storage
Alpine Linux
Install Python
RUN apk update && apk upgrade RUN apk add python3 py3-pip
This page has been accessed:-
Today: 1
Yesterday: 1
Until now: 399