To run a docker image
press the run button in the UI
A docker container is basically
a background process thats running an image. Like a server.
An image is
all the code of the OS (binaries, config), the dependencies, and anything you copied in.
To create a new image, you need to
create a Dockerfile
The FROM section in the Dockerfile defines
which parent image your new image will start from.
The EXPOSE section in the Dockerfile defines
the port in your container will be allowed to be proxied to the outside world.
To make a docker container accept requests on a particular port, you need to
put EXPOSE 8000 in the dockerfile so it will be permitted to to share that port.
Run the docker image in a container and set a host proxy port which will map to the EXPOSE port.
For development, to get updates to project files to get seen by the docker image, you need to use
a volume
a volume is
a path to a directory that your container will be able to access in real time from your main computer in its container. A portal.
A dockerfile is basically
the list of instructions for creating a new docker image
Before deploying, you must
remove your volume and create a new image with the files actually copied into the image.
Volumes do not
save into the image.
The COPY section in the dockerfile defines
files to copy from the local computer to the container computer.
e.g. COPY myDir /myContainerDir
The CMD section in the dockerfile defines
a command you want to run in the container’s WORKDIR
Must be a list of arguments
e.g. CMD [‘echo’, ‘string’]
the WORKDIR section in the dockerfile defines the
folder that you want docker to create and cd into so it is the working directory. Basically mkdir my_directory and cd my_directory combined.
CMD commands will run in the WORKDIR
the ADD section in the dockerfile defines
a file that you want copied into the image
ADD and COPY are the same except
ADD can also accept a URL
A base image is
the first image in a lineage of parent images
Simplest example app
Copied separately from main.py because each step creates a cache
app = Flask(__name__)
@app.get(“/”)
def index():
return “<h1>Hello, world!</h1>”
if __name__ == “__main__”:
app.run(host=”0.0.0.0”, port=8000)
Then build the image
docker build -t my_image_name ./path/to/project_dir
And run it from docker desktop using a proxy host port