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
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 -con Linux orcmd /S /Con Windows)RUN ["executable", "param1", "param2"](exec form)
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 CMDwill take effec
ENV
ADD
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
Last updated