dockerfile Dockerfile示例

Dockerfile
# Image to base on
FROM ImageName
# Example
FROM ubuntu:latest

# Person to contact regards Image
LABEL maintainer="email@domain.tld"
# Example
LABEL maintainer=andrey.ryoo@gmail.com

# To run command during image building
RUN shell programm
RUN ["shell programm", "arg1", "arg2"]
# Example
RUN apt-get update
RUN ["apt-get", "update"]

# To run command after image is built
CMD shell programm
CMD ["shell programm", "arg1", "arg2"]
# Example
CMD /bin/bash script.sh
CMD ["/bin/bash", "script.sh"]

# To make container to be reacheble
EXPOSE port or port/protocol
# Example
EXPOSE 80
EXPOSE 80/tcp

# To set environment variable avalible during container runtime
ENV key value
# Example
ENV app_location /home/username/app/

# To set variables availible only during build
ARG key=value
# Example
ARG language=ru_RU.UTF-8

# To add file/s to the image
ADD <src> <dst>
# Example
ADD test.txt app/ # Uses WORKDIR
ADD test.txt /home/userName/dir

# To sync folders/files in Container
COPY <src> <dst>
# Example
COPY test.txt app/ # Uses WORKDIR
COPY test.txt /home/userName/dir

# To run commands on users demand
USER user
# Example
USER root
User user:users

#To set Working directory
WORKDIR <path>
# Example
WORKDIR /home/user/

dockerfile 网络服务器与php5.6

网络服务器与php5.6

Dockerfile
FROM ubuntu:16.04

# Install Apache PHP + extensions
RUN apt-get update && apt-get install -y software-properties-common \
    python-software-properties
RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
RUN apt-get update && apt-get install -y \
    apache2 \
    php5.6 \
    php5.6-mysql \
    php5.6-mbstring

RUN apt-get install -y git iproute2 vim

# Install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
    && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
    && php -r "unlink('composer-setup.php');"

# Configure Apache
ADD apache/www.domaine-legal.com.conf /etc/apache2/sites-available/
RUN a2ensite www.domaine-legal.com
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
RUN echo 'date.timezone = "Europe/Paris"' >> /etc/php/5.6/apache2/php.ini

# Install node modules
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN npm install bower -g
RUN echo "{ \"allow_root\": true }" > /root/.bowerrc

WORKDIR /var/www/html

EXPOSE 80

CMD /usr/sbin/apache2ctl -D FOREGROUND

dockerfile Docker中的MongoDB副本集

Docker中的MongoDB副本集

run.ps1
#!/bin/sh
docker run --rm -it -p 27000:27000 -p 27001:27001 -p 27002:27002 mongo:latest
init.rs.js
var cfg = {
    _id: "xconnect",
    members: [
        { _id: 0, host: "localhost:27000" },
        { _id: 1, host: "localhost:27001" },
        { _id: 2, host: "localhost:27002" }
    ]
};

rs.initiate(cfg);
build.ps1
#!/bin/sh
docker build --rm -f Dockerfile -t mongo:latest .
Dockerfile
FROM ubuntu:16.04

COPY 3.6.0-rc4/bin /mongo
COPY init.rs.js /mongo

RUN mkdir data && \
    mkdir data/db0 && \
    mkdir data/db1 && \
    mkdir data/db2 && \
    mkdir logs && \
    apt-get update && \
    apt-get install -y sudo && \
    apt-get install -y libcurl3 && \
    apt-get install -y libsnmp30 && \
    chmod +x mongo/mongo*

ENV PATH="/mongo:${PATH}"

WORKDIR /mongo

VOLUME /data

EXPOSE 27000
EXPOSE 27001
EXPOSE 27002

ENTRYPOINT  mongod --replSet xconnect --dbpath /data/db0 --logpath /logs/log0 --logappend --oplogSize 64 --noauth --port 27002 --bind_ip_all --fork && \
            mongod --replSet xconnect --dbpath /data/db1 --logpath /logs/log1 --logappend --oplogSize 64 --noauth --port 27001 --bind_ip_all --fork && \
            mongod --replSet xconnect --dbpath /data/db2 --logpath /logs/log2 --logappend --oplogSize 64 --noauth --port 27000 --bind_ip_all --fork && \
            mongo  --port 27000 /mongo/init.rs.js && \
            mongo --port 27000

dockerfile 码头工人实用文件

#docker <br/> <br/>一些基本的docker实用配置文件和命令

docker-compose.yml
version: '3'
services:
  ubuntu:
    build: ./dockerfile/ubuntu
    #image: ubuntu:16.04
    volumes:
    - ./files/theia:/theia
    - ./files/ssh_config:/root/.ssh
    ports:
    - "2222:22"
    
Dockerfile
FROM       ubuntu:16.04
MAINTAINER color.fuzzy

RUN apt-get update

RUN apt-get install -y openssh-server
RUN apt-get install -y python-pip
RUN apt-get install -y python-dev build-essential
RUN apt-get install -y libmemcached-dev libxml2-dev libxslt1-dev libffi-dev libssl-dev libgeos-dev binutils libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
RUN pip install virtualenv
RUN mkdir /var/run/sshd

RUN echo 'root:root' | chpasswd

RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config

EXPOSE 22

CMD    ["/usr/sbin/sshd", "-D"]

dockerfile dockerfile.md

dockerfile.md
### Dockerfile VOLUME ###

Định nghĩa VOLUME trong Dockerfile sẽ:
* Expose folder/directory được tạo bởi container ra đường dẫn trên host: `/var/lib/docker/volumes/[container_id]/_data/`
Note: `_data` được gọi là *"mount point"*

Run container với lệnh: `docker run --rm image`

Khi container được run, ta có thể check volume được tạo bởi container bằng câu lệnh: `docker volume ls`
Khi container exited, volume sẽ mất do ta định nghĩa cờ `--rm` ở câu lệnh `docker run`, do đó container và volume của nó sẽ được remove hoàn toàn.

dockerfile 烧瓶-搬运工-撰写-示例

烧瓶-搬运工-撰写-示例

docker-compose.yml
version: '2'

services:
    web:
        environment:
            - FLASK_CONFIG=production
        build: ./app/
        volumes:
            - .:/code
            - /var/uploads/
        command: gunicorn -w 2 -b :8000 manage:app
        depends_on:
            - redis
            - postgres
    redis:
        image: redis:alpine
        ports:
            - "6379:6379"
    data:
        image: postgres:alpine
        volumes:
            - /var/lib/postgresql
        command: "true"
    postgres:
        restart: always
        image: postgres:alpine
        volumes_from:
            - data
        ports:
            - "5432:5432"
    nginx:
        restart: always
        image: nginx:alpine
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - ./nginx.conf:/etc/nginx/nginx.conf
        volumes_from:
            - web
            - certbot
        links:
            - web:web
        depends_on:
            - certbot
        certbot:
            image: henridwyer/docker-letsencrypt-cron
            volumes:
                - /certs:/certs
            restart: always
            environment:
                - DOMAINS = example.com
                - EMAIL = EMAIL@EMAIL.COM
                - CONCAT = false
                - SEPARATE = false
Dockerfile
FROM python:3.5-alpine

RUN apk add --no-cache build-base libffi-dev postgresql-dev

WORKDIR /code
ADD ./requirements.txt /code/requirements.txt
RUN pip install -r requirements.txt
ADD . /code

dockerfile 用于dcron的Dockerfile(关键字:cron,crontab)

用于dcron的Dockerfile(关键字:cron,crontab)

index.md
In `scripts/` sub-directory are custom scripts called by crontab, e.g. `arangodb-snapshot.sh` for backingup arango database daily:

```shell
#!/bin/bash
set -e

BASE_DUMP_DIR=/var/lib/arangodb3/backups
CUR_DUMP_DIR="mydb-dump-`date '+%Y%m%d%H%M%S'`"
TAR_BALL="${CUR_DUMP_DIR}.tgz"

mkdir -p "$BASE_DUMP_DIR"
cd "$BASE_DUMP_DIR"

docker exec my-arango arangodump \
    --server.database=mydb \
    --server.username='root' --server.password='' \
    --output-directory="${BASE_DUMP_DIR}/${CUR_DUMP_DIR}"

tar -cvzf "$TAR_BALL" "$CUR_DUMP_DIR"

## Send to cloud-storage

## Notify success

```

Run:

```shell
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/amidala/arangodb3:/var/lib/arangodb3 cron
```
docker-entry.sh
#!/bin/sh
set -e

# see: https://github.com/dubiousjim/dcron/issues/13
# ignore using `exec` for `dcron` to get another pid instead of `1`
# exec "$@"
"$@"
Dockerfile
FROM docker

# Ref: https://github.com/xordiv/docker-alpine-cron

MAINTAINER wonderbeyond@gmail.com

RUN apk add --no-cache dcron bash tar
RUN mkdir -p /var/log/cron && touch /var/log/cron/cron.log
RUN rm -rf /etc/cron.d && mkdir -p /etc/cron.d

COPY ./docker-entry.sh /usr/local/bin
COPY ./scripts /usr/local/bin

RUN chmod +x /usr/local/bin/*

COPY ./crontabs/* /etc/cron.d

ENTRYPOINT ["docker-entry.sh"]
CMD ["crond", "-f", "-s", "/etc/cron.d", "-L", "/var/log/cron/cron.log"]

dockerfile 高山dockerfile与构建要领

高山dockerfile与构建要领

Dockerfile
FROM node:7.8-alpine
LABEL maintainer "Mark Niehe<mark@niehe.ca>"

# Install all build dependencies
# Add bash for debugging purposes
RUN apk update \
    && apk add --virtual build-dependencies \
        build-base \
        gcc \
        wget \
        git \
    && apk add \
        bash

WORKDIR /app
COPY package.json .

# Install all npm dependencies
# Cleanup
RUN npm install --silent --production \
    && apk del build-dependencies \
    && rm -rf /var/cache/apk/*

# Copy entire app over
COPY . /app

EXPOSE 3000

CMD ["node", "index.js"]

dockerfile Dockerfile

Dockerfile
FROM fernandopetry/phalcon:v1
MAINTAINER Fernando Petry
WORKDIR /var/www/html
RUN service apache2 start
RUN service redis-server start
RUN service memcached start
EXPOSE 80

dockerfile Dockerfile:Python3 + Django + Gunicorn,带有自定义的apt&pypi镜像

Dockerfile:Python3 + Django + Gunicorn,带有自定义的apt&pypi镜像

Dockerfile
FROM python:3

RUN /bin/echo -e \
"deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib\n"\
"deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib\n"\
"deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib\n"\
"deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib\n"\
> /etc/apt/sources.list

# build deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    python3-dev \
    libjpeg62-turbo libjpeg62-turbo-dev zlib1g zlib1g-dev \
    libpcre3-dev \
    git \
    openssh-client

# for pip install from git repos.
COPY ./myproj.pem /root/.ssh/id_rsa
RUN chmod 400 /root/.ssh/id_rsa
RUN /bin/echo -e "Host *\n\tStrictHostKeyChecking no" > /root/.ssh/config

RUN mkdir -p ~/.pip && /bin/echo -e \
"[global]\n"\
"index-url = http://mirrors.aliyun.com/pypi/simple/\n"\
"trusted-host = mirrors.aliyun.com\n"\
> ~/.pip/pip.conf

COPY ./requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt

# Web app source code
COPY ./myproj /code
WORKDIR /code

ENV APP_ENV=prod

CMD [ \
    "gunicorn", \
    "--bind=0.0.0.0:8000", \
    "--worker-class=gthread", \
    "--workers=5", \
    "--threads=6", \
    "--access-logfile=-", \
    "myproj.wsgi" \
]