Dockerfile
Check out https://hub.docker.com/search/?type=image for bases
Dockerfile
A Docker image consists of read-only layers each of which represents a Dockerfile instruction
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
Commands
ADD
COPY
ENV
EXPOSE
FROM
LABEL
STOPSIGNAL
USER
VOLUME
WORKDIR
Use env variables you declare with env like $foo
RUn
RUN has 2 forms:
RUN <command>
(shell form, the command is run in a shell, which by default is/bin/sh -c
on Linux orcmd /S /C
on Windows)RUN ["executable", "param1", "param2"]
(exec form)
RUN mkdir -p /usr/src/things \ #multiple line syntax
&& curl -SL http://example.com/big.tar.gz
CMD
The CMD
instruction has three forms:
CMD ["executable","param1","param2"]
(exec form, this is the preferred form)CMD ["param1","param2"]
(as default parameters to ENTRYPOINT)CMD command param1 param2
(shell form)
There can only be one CMD
instruction in a Dockerfile
. If you list more than one CMD
then only the last CMD
will take effec
ENV
ENV myName="John Doe"
ADD
ADD test relativeDir/ # adds "test" to `WORKDIR`/relativeDir/
ADD test /absoluteDir/ # adds "test" to /absoluteDir/
COPY
Like ADD, but without urls and tar handling, should be used when you dont need ADD
Dockerignore
Add things to .dockerignore
file to prevent copying
node_modules
npm-debug.log
Last updated