2020年9月14日星期一

Introduction of Docker nginx

 1. Docker run nginx:alpine with --mount

## mkdir from folder in dockerhost before --mount,
$ mkdir -p /var/www
$ mkdir -p /var/nginx/conf
## -p :make parent directories as needed.
## run nginx. Be careful:no space on every line head.
docker run --name mynginx2 \
--mount type=bind,\
source=/var/www,\
target=/usr/share/nginx/html,readonly \
--mount type=bind,\
source=/var/nginx/conf,\
target=/etc/nginx/conf,readonly \
-dp 8082:80 nginx:alpine

volume path must be absolute. like: -v ~/vuechat:/vuechat

## static html,js,css will be saved in /var/www/ by docker host
## nginx config will be save in /var/nginx/conf by docker host 
## Readonly from docker container. and read-write from dock host

 2. Docker Log Saved path:
    /var/lib/docker/containers/container-ID/container-ID-json.log 
$ docker ps -a 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c7f35ce5ec0b        nginx:alpine        "/docker-entrypoint.…"   15 minutes ago      Up 15 minutes       0.0.0.0:8082->80/tcp   mynginx2

$ ls /var/lib/docker/containers
c7f35ce5ec0b78abac3b19c6a31bac47282a774909f29406900609a30aaa6248

$ ls /var/lib/docker/containers/c7f*
c7f35ce5ec0b78abac3b19c6a31bac47282a774909f29406900609a30aaa6248-json.log
checkpoints
config.v2.json
hostconfig.json
hostname
hosts
mounts
resolv.conf
resolv.conf.hash

$cat /var/lib/docker/containers/c7f*/c7f*.log
...

{"log":"/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration\n","stream":"stdout","time":"2020-09-14T07:32:48.734972228Z"}
{"log":"/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/\n","stream":"stdout","time":"2020-09-14T07:32:48.735004429Z"}
{"log":"/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh\n","stream":"stdout","time":"2020-09-14T07:32:48.737170543Z"}
{"log":"10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf\n","stream":"stdout","time":"2020-09-14T07:32:48.743271983Z"}
{"log":"10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf\n","stream":"stdout","time":"2020-09-14T07:32:48.758506583Z"}
{"log":"/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh\n","stream":"stdout","time":"2020-09-14T07:32:48.758856885Z"}
{"log":"/docker-entrypoint.sh: Configuration complete; ready for start up\n","stream":"stdout","time":"2020-09-14T07:32:48.763013513Z"}

3. Docker nginx Dockerfile 

FROM nginx
RUN rm /etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY content /usr/share/nginx/html
COPY conf /etc/nginx
VOLUME /var/nginx/log

没有评论: