Standardized packaging for software and dependencies
Isolate apps from each other
share the same OS kernel
Works for all major Linux distributions.
Note: Docker Containers are NOT VMs
Docker Containers are NOT VMs
Dockerfile:
Series of instructions to build Docker Images.
We define our app's environment with a Dockerfile so it can be reproduced anywhere.
Example of Dockerfile
Dockerfile
# Our Base Image
FROM alpine:latest
# Install Python and pip
RUN apk --update py-pip
# Upgrade pip
RUN pip install --upgrade pip
# Install Python modules needed by the Python app
COPY requirements.txt /user/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt
# Copy files required for the app to run
COPY app.py /user/src/app/
COPY templates/index.html /usr/src/app/templates/
# Tell the port number the container should expose
EXPOSE 8000
# Run the application
CMD ["python", "/usr/src/app/appy.py"]
Each Dockerfile creates a layer
.....
Install Requirements
Copy Requirements
Upgrade Pip
Install Python and Pip
Alpine Linux
Kernel
Docker Compose:
Compose is a tool for defining and running multi-container Docker applications. Use a YAML file to configure application services. Compose works in all environments: production, staging, development, testing, as well as CI workflows. With a single command, we can create and start all services from our configuration.
We define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
Example of Docker compose.
Difference between Docker Compose Vs Dockerfile
A Dockerfile is a simple text file that contains the commands a user could call to assemble an image whereas Docker Compose is a tool for defining and running multi-container Docker applications.
Docker Compose defines the services that make up your app in docker-compose.yml so they can be run together in an isolated environment. It gets an app running in one command by just running docker-compose up. Docker-compose uses the Dockerfile if one adds the build command to your project’s docker-compose.yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.