Skip to content

Instantly share code, notes, and snippets.

@matt-baker
Last active August 29, 2015 14:25
Show Gist options
  • Save matt-baker/0eb5e9223cc72b77ca5a to your computer and use it in GitHub Desktop.
Save matt-baker/0eb5e9223cc72b77ca5a to your computer and use it in GitHub Desktop.
Sample Docker development commands
# Example is for a Python Flask app
# Assumes your project is structured as:
/project/Dockerfile
/project/app/... #Source code that you can edit
# Dockerfile snippet -----------------------------
# Add /app as /webroot/app in the container
ADD ./app /webroot/app
# Commands to use Docker -----------------------------
# CD to dir
cd /project
# Create a docker base image called dev-image using the Dockerfile in /project
docker build -t=dev-image .
# Create a docker container called dev-container that is open on port 8001
# Mount local files as /webroot/app in the container. This overrides the ADD command in the Dockefile
# Use dev-image as the image for the container.
docker create --name=dev-container -t -i -p 0.0.0.0:8001:8001 -v /home/some-user/webroot/app:/webroot/app dev-image /bin/bash
# Start dev-container and attach to it
docker start -a -i dev-container
# Once the container starts, you are free to start up your server/edit the source code in /project/app etc.
# In this case I'm using Python/gunicorn.
# The app should be visible on localhost:8001 or server-name:8001
gunicorn --reload -w 4 -b 0.0.0.0:8001 app:app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment