dockerfile Dockerfile

Dockerfile
FROM python:2.7.12
RUN groupadd flaskgroup && useradd -m -g flaskgroup -s /bin/bash flask
RUN mkdir -p /home/flask/app/web
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list
RUN apt-get update && apt-get install curl -y
WORKDIR /home/flask/app/web
COPY requirements.txt /home/flask/app/web
RUN pip install --no-cache-dir -r requirements.txt
COPY . /home/flask/app/web
RUN chown -R flask:flaskgroup /home/flask
USER flask
EXPOSE 5000
ENTRYPOINT ["python"]
CMD ["dbz.py"]

dockerfile 用于多阶段构建Ruby应用程序的Dockerfile,在构建时需要Node(信用:https://github.com/gomex)

用于多阶段构建Ruby应用程序的Dockerfile,在构建时需要Node(信用:https://github.com/gomex)

Dockerfile
# Dockerfile for a multi-stage build of a Ruby app which needs Node at build time
#
# Thanks to https://github.com/gomex for sharing

FROM ruby:2.5.1 as builder

RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - &&\
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

ARG NODE_DATE_INSTALL=20180710

RUN apt-get update \
    && apt-get install -y locales \
                        graphviz \
                        imagemagick \
                        postgresql-client-9.6 \
                        yarn \
                        nodejs \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && /usr/sbin/locale-gen &&\
    rm -rf /var/lib/apt/lists/*

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ARG BUNDLE_GITHUB__COM
ENV BUNDLE_GITHUB__COM $BUNDLE_GITHUB__COM
ENV GEM_HOME /gems/vendor
ENV GEM_PATH /gems/vendor
ENV GEM_SPEC_CACHE /gems/specs
ENV BUNDLE_APP_CONFIG /gems/vendor
ENV BUNDLE_PATH /gems/vendor
ENV BUNDLE_BIN /gems/vendor/bin
ENV PATH /app/bin:/gems/vendor/bin:$PATH
ARG RAILS_ENV
ENV RAILS_ENV=$RAILS_ENV

ENV APP_ROOT /app

WORKDIR $APP_ROOT/

RUN mkdir -p /gems

RUN groupadd -r app \
    && groupmod -g 1000 app \
    && useradd -g app -ms /bin/bash app \
    && chown app $APP_ROOT \
    && chown -R app /gems

USER app

FROM builder as install

USER app

COPY Gemfile.lock $APP_ROOT/
COPY Gemfile $APP_ROOT/
COPY package-lock.json $APP_ROOT/
COPY package.json $APP_ROOT/

RUN bundle install
RUN yarn install

FROM install as preprod

USER root

ARG SECRET_KEY_BASE
ENV SECRET_KEY_BASE=$SECRET_KEY_BASE

COPY . /$APP_ROOT/

RUN bundle exec rails assets:precompile


# Packaging final app w/o node_modules & the development tools
FROM paycertify/ruby:2.5.1-slim as prod

LABEL maintainer="Rafael Gomes <rafael.gomes@paycertify.com>"
LABEL name="app"

ENV GEM_HOME /gems/vendor
ENV GEM_PATH /gems/vendor
ENV GEM_SPEC_CACHE /gems/specs
ENV BUNDLE_APP_CONFIG /gems/vendor
ENV BUNDLE_PATH /gems/vendor
ENV BUNDLE_BIN /gems/vendor/bin
ENV PATH /app/bin:/gems/vendor/bin:$PATH

WORKDIR /app/

RUN groupadd -r app \
    && groupmod -g 1000 app \
    && useradd -g app -ms /bin/bash app

COPY --from=preprod /usr/local/bundle/ /usr/local/bundle/
COPY --from=preprod /app/ /app/
COPY --from=preprod /gems/ /gems/
RUN chown -R app /gems
RUN chown -R app /app/

USER app

EXPOSE 3000

CMD ["bundle","exec","rails","server","-b","0.0.0.0"]

dockerfile Tomcat TomEE Docker调试模式

如何在调试模式下运行Tomcat / TomEE docker容器

tomcatTomEEDockerDebug.sh
docker run -it -p 8080:8080 -p 8000:8000 -e CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000" tomcat:9.0.17-jre11

dockerfile Dockerfile

Dockerfile
FROM node:9 AS build
WORKDIR /srv
ADD package.json .
RUN npm install

FROM node:9-slim
COPY --from=build /srv .
ADD . .
EXPOSE 3000
CMD ["node", "index.js"]

dockerfile 用于构建MVIG-SJTU / AlphaPose的Dockerfile

用于构建MVIG-SJTU / AlphaPose的Dockerfile

Dockerfile
# based on [sberryman/Dockerfile.yml](https://gist.github.com/sberryman/82a6d13a44f9c4a3bfaf9263b36c92ed)
# You need the cuda drivers and [nvidia-docker](https://github.com/NVIDIA/nvidia-docker)
#
# build with
#       docker build .
#
# run with
#       docker run --runtime=nvidia -it --rm -v $(realpath ./data):/root/AlphaPose/data [imagename] ./run.sh --indir=/root/AlphaPose/data/in/ --outdir=data/out

FROM nvidia/cuda:8.0-cudnn5-devel

# Supress warnings about missing front-end. As recommended at:
# http://stackoverflow.com/questions/22466255/is-it-possibe-to-answer-dialog-questions-when-installing-under-docker
ARG DEBIAN_FRONTEND=noninteractive

# Install some dependencies
RUN apt-get update && \
    apt-get install -y \
      apt-utils \
      git \
      curl \
      unzip \
      openssh-client \
      wget \
      build-essential \
      cmake \
      libboost-all-dev \
      libffi-dev \
      libfreetype6-dev \
      libhdf5-dev \
      libjpeg8-dev \
      liblcms2-dev \
      libopenblas-dev \
      liblapack-dev \
      libpng12-dev \
      libssl-dev \
      libtiff5-dev \
      libwebp-dev \
      libzmq3-dev \
      nano \
      pkg-config \
      libavcodec-dev \
      libavformat-dev \
      libswscale-dev \
      libtheora-dev \
      libvorbis-dev \
      libxvidcore-dev \
      libx264-dev \
      yasm \
      libopencore-amrnb-dev \
      libopencore-amrwb-dev \
      libv4l-dev \
      libxine2-dev \
      libtbb-dev \
      libeigen3-dev \
      python3.5 \
      python3.5-dev \
      python3-pip \
      python3-tk \
      zlib1g-dev \
      libprotobuf-dev \
      libleveldb-dev \
      libsnappy-dev \
      libhdf5-serial-dev \
      protobuf-compiler \
      liblmdb-dev \
      libgoogle-glog-dev \
      && \
  apt-get clean && \
  apt-get autoremove && \
  rm -rf /var/lib/apt/lists/*


# python dependencies
RUN apt-get update && \
    apt-get install -y python-pip && \
    pip install --no-cache-dir --upgrade Cython numpy python-dateutil && \
    apt-get clean && \
    apt-get autoremove && \
    rm -rf /var/lib/apt/lists/*

# alphapose deps
RUN cd /root && \
    git clone --depth=1 https://github.com/MVIG-SJTU/AlphaPose.git && \
    cd AlphaPose/human-detection/lib/ && \
    make clean && \
    make && \
    cd newnms/ && \
    make

# Tensorflow 1.2.1 - GPU
RUN pip install --no-cache-dir --upgrade \
    "https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp27-none-linux_x86_64.whl"

# torch
RUN cd /root && \
    git clone https://github.com/torch/distro.git /root/torch --recursive && \
    cd /root/torch && \
    sed -i 's/sudo\ //' install-deps && \
    apt-get update && \
    bash install-deps && \
    ./install.sh -b && \
    apt-get install -y python-tk && \
    apt-get clean && \
    apt-get autoremove && \
    rm -rf /var/lib/apt/lists/*

# get the exports (had to manually stop build here and read the below file)
# i'm sure there is a better and more automated way
# file: `cat /root/torch/install/bin/torch-activate`
ENV LUA_PATH='/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/root/torch/install/share/lua/5.1/?.lua;/root/torch/install/share/lua/5.1/?/init.lua;./?.lua;/root/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua' \
    LUA_CPATH='/root/.luarocks/lib/lua/5.1/?.so;/root/torch/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so' \
    PATH="/root/torch/install/bin:$PATH" \
    LD_LIBRARY_PATH="/root/torch/install/lib:$LD_LIBRARY_PATH" \
    DYLD_LIBRARY_PATH="/root/torch/install/lib:$DYLD_LIBRARY_PATH" \
    LUA_CPATH="/root/torch/install/lib/?.so;$LUA_CPATH"

# finish up alphapose
RUN luarocks install hdf5 && \
    cd /root/AlphaPose && \
    chmod +x install.sh && \
    ./install.sh
RUN pip install --upgrade pip
# Common libraries
RUN pip --no-cache-dir install \
    Pillow scipy sklearn scikit-image pandas matplotlib requests pika h5py

RUN cd /root/AlphaPose && \
    chmod +x fetch_models.sh && \
    ./fetch_models.sh

WORKDIR "/root/AlphaPose"

dockerfile Docker多相构建

Dockerfile
FROM node:alpine as builder
WORKDIR /app

COPY package.json .
RUN npm install

COPY . .

RUN npm run build


FROM nginx

ENV PORT 3000
EXPOSE $PORT

COPY nginx/default.conf /etc/nginx/conf.d/default.conf

COPY --from=builder /app/build /usr/share/nginx/html

dockerfile Nest.js启动项目片段

docker-compose.dev.yml
# docker-compose file for development

version: '3'

services:
  app:
    build:
      context: .
    ports:
      - '3000:3000'
    volumes:
      - ./:/app
    command: npm run start:dev
    env_file:
      - .env
Dockerfile.dev
# Development docker file for Node.js

FROM node:10-alpine

COPY package.json .

RUN npm install

RUN mkdir /app

WORKDIR /app

COPY ./ /app

RUN adduser -D user
USER user

dockerfile 关于码头工人

docker-compose.yml
version: '3'

services:
  db:
    image: postgres:9.6.5
    volumes:
      - postgres_data:/var/lib/postgresql/data/
  redis:
    image: "redis:alpine"
  web:
    build: .
    command: bash -c "python /code/manage.py migrate --noinput && python /code/manage.py runserver 0.0.0.0:8000"
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
      - redis
  celery:
    build: .
    command: celery -A proj worker -l info
    volumes:
      - .:/code
    depends_on:
      - db
      - redis
  celery-beat:
    build: .
    command: celery -A proj beat -l info
    volumes:
      - .:/code
    depends_on:
      - db
      - redis

volumes:
  postgres_data:
Dockerfile
FROM python:3.6

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /code/requirements.txt
RUN pip install -r /code/requirements.txt

COPY . /code/
WORKDIR /code/

EXPOSE 8000

dockerfile 在高山码头工人的pyenv

在高山码头工人的pyenv

Dockerfile
ARG PYTHON_VERSION=3.7.0-alpine3.8

FROM python:${PYTHON_VERSION} as builder

RUN apk add --update make \ 
    cmake \
    g++

RUN apk add \
    git \
    bash \
    build-base \
    linux-headers \
    bzip2 \
    bzip2-dev \
    sqlite-dev \
    zlib-dev \
    curl \
    libffi-dev \
    ncurses-dev \
    openssl-dev \
    readline-dev \
    tk-dev \
    xz-dev \
    zlib-dev


RUN pip install pytest tox
RUN pip install tox-globinterpreter

ENV HOME  /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

RUN curl https://pyenv.run | bash
RUN pyenv install 3.5.6
RUN pyenv global 3.5.6
RUN pyenv install 3.6.8
RUN pyenv virtualenv -p python3.5 3.5.6 py35
RUN pyenv virtualenv -p python3.6 3.6.8 py36


WORKDIR /app
ENTRYPOINT [ "bash" ]

dockerfile Docker XDebug

docker_xdebug.md
# Docker and XDebug configuration

## PHP Dockerfile
Below is the PHP Dockerfile with the XDebug configuration. 

The `host.docker.internal` pseudo domain is pointing back to the docker host. Do not use directly the ip address because the host ip address is changing and it wont work in all the cases.

The default xdebug port `9000` is changed to `9001` to avoid conflicts with `php-fpm`.

```
# Install xdebug
RUN pecl install xdebug \
    && docker-php-ext-enable xdebug \
    && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_log=/tmp/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
\!h     && echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
\!h     && echo "xdebug.remote_host=host.docker.internal">> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.profiler_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \

    && echo "xdebug.profiler_output_dir=/tmp/snapshots" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
\!h     && echo "xdebug.idekey=VSCODE" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.profiler_enable_trigger=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
```
## docker-composer.yml
Because we need our application to connect back to the docker host we do
not forward the `9001` port. Otherwise the container will connect back to itself.

The `${PROJECT_PATH}` should be set in the `.env` file inside your docker-compose project.

```
     php:
         environment:
             - ENVIROMENT=dev
             - XDEBUG_CONFIG="idekey=VSCODE"
         build: "./containers/php"
         hostname: "phpxdebug"
         container_name: "phpxdebug"
         volumes:
\!h              - "${PROJECT_PATH}:/var/www/html"
         ports:
             - "9000:9000"
```

## VS Code config
Below is the __VS Code__. The default __XDebug__ port should be replaced with the
`9001` so that we avoid that `php-fpm` and `xdebug` are having confilicts on the same port.

```
{
  "name": "Listen for XDebug",
  "type": "php",
  "request": "launch",
\!h   "port": 9001,
  "log": true,
\!h   "pathMappings": {
\!h   "/var/www/html": "${workspaceRoot}"
\!h   }
}
```

### Debug
In case that something is not working you check the `/tmp/xdebug.log` path on the container. Be sure that xdebug has write permissions on the file.
Dockerfile
FROM php:7.2-fpm

MAINTAINER Maciej Slawik <maciekslawik@gmail.com>

RUN apt-get update && apt-get install -y \
    unzip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && composer --version

# Set timezone
RUN rm /etc/localtime \
    && ln -s /usr/share/zoneinfo/Europe/Warsaw /etc/localtime \
    && "date"

# Install PDO
RUN apt-get install -y libpq-dev \
    && docker-php-ext-install pdo pdo_mysql pdo_pgsql

RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
        vim \
    && docker-php-ext-install -j$(nproc) iconv bcmath \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

RUN apt-get install -y zlib1g-dev libicu-dev g++ && \
    docker-php-ext-configure intl && \
    docker-php-ext-install intl zip && \
    apt-get purge -y g++

RUN apt-get install -y libxslt-dev
RUN docker-php-ext-install xsl soap mysqli

# Install xdebug
RUN pecl install xdebug \
    && docker-php-ext-enable xdebug \
    && echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_log=/tmp/xdebug.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_host=host.docker.internal">> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.profiler_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.var_display_max_depth=5" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.var_display_max_children=256" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.var_display_max_data=1024" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.profiler_output_dir=/tmp/snapshots" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.idekey=VSCODE" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.profiler_enable_trigger=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo 'alias sf="php app/console"' >> ~/.bashrc \
    && echo 'alias sf3="php bin/console"' >> ~/.bashrc \
    && echo 'alias mage="php bin/magento"' >> ~/.bashrc

# Install Redis extension
RUN pecl install -o -f redis \
    && rm -rf /tmp/pear \
    && echo "extension=redis.so" > /usr/local/etc/php/conf.d/docker-php-ext-redis.ini

# Install MongoDB extension
RUN pecl install mongodb \
    && rm -rf /tmp/pear \
    && echo "extension=mongodb.so" >> /usr/local/etc/php/conf.d/docker-php-ext-mongodb.ini

# Set ID
RUN usermod -u 1000 www-data

# Add aliases for xdebug control
RUN echo 'alias xoff="mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.off && kill -USR2 1"' >> ~/.bashrc
RUN echo 'alias xon="mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.off /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && kill -USR2 1"' >> ~/.bashrc

# Change memory limit
RUN echo 'memory_limit = 2G ' >> /usr/local/etc/php/php.ini

# Install Blackfire probe
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
    && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
    && mkdir -p /tmp/blackfire \
    && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
    && mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
    && printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/docker-php-ext-blackfire.ini \
    && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

# Install Blackfire CLI executable
RUN mkdir -p /tmp/blackfire \
    && curl -A "Docker" -L https://blackfire.io/api/v1/releases/client/linux_static/amd64 | tar zxp -C /tmp/blackfire \
    && mv /tmp/blackfire/blackfire /usr/bin/blackfire \
    && rm -Rf /tmp/blackfire