Skip to content

Instantly share code, notes, and snippets.

@karthikax
Created December 27, 2019 17:33
Show Gist options
  • Save karthikax/6274ef18a5fe2ad9389bbdeddcfba25f to your computer and use it in GitHub Desktop.
Save karthikax/6274ef18a5fe2ad9389bbdeddcfba25f to your computer and use it in GitHub Desktop.
Docker basics
FROM python:3
# From here: https://hub.docker.com/_/python
# Python preinstalled
# You can use any image from docker hub
WORKDIR /usr/src/app
COPY my_file.py ./
# Copy any file or directory here if needed.
RUN echo "Run any shell command here"
# like apt-get install
# pip install etc.
CMD [ "python", "./my_file.py" ]
# Install docker in your local machine
# Save the above Dockerfile in local
# In the same directory run the following to build your docker image
docker build -t my-python-app:latest .
# This will build and save image in local with image name my-python-app and tag latest
# Now you can run the container from that image by using following command
docker run -it my-python-app:latest
# At runtime you can
# - mount local folders into container using -v flag
# - expose port into host machine using -p flag
# - run in detached mode using -d flag
# etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment