Рет қаралды 1,412
Docker Installation Guide
Ubuntu:
docs.docker.co...
All Flavors:
docs.docker.co...
========
Basic Docker Commands:
1. Pull docker image:
docker pull IMAGE_NAME
2. Run Docker container:
docker run -it IMAGE_NAME OPTIONAL_COMMANDS
3. Build Docker image:
docker build -t IMAGE_NAME:TAG_NAME .
(Make sure to keep the Dockerfile in the same folder or mention the path)
4. List all running containers:
docker ps
5. List all containers:
docker ps -a
6. Remove a container:
docker rm CONTAINER_ID
7. Remove an image from local image repository:
docker rmi IMAGE_ID
========
Commonly used Dockerfile Directives:
FROM: Inherit Base Image
MAINTAINER: Name and email of maintainer of the image
ENV: Setup Environment variables usable within the container
COPY: Copy files to Containers
USER: Which user runs the container processes
WORKDIR: What's my working directory within container?
EXPOSE: Expose the port where the application runs
VOLUME: Mount Host OS's Filesystem as a mount point within the container
CMD: Run the application within container
========
Directory Structure used in Demo:
docker_test/Dockerfile
docker_test/requirements.txt
docker_test/src/sample_app.py
========
Dockerfile used:
FROM ubuntu
MAINTAINER 2DPointTechie "john.doe@somemail.com"
RUN apt-get update -y
RUN apt-get install python3 -y
RUN apt-get install python3-pip python3-dev -y
WORKDIR /
COPY ./requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt
COPY . /
EXPOSE 5000
CMD ["python3", "src/sample_app.py"]
========
Sample webapp using flask:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def helloWorld():
return "Hello World"
if _name_ == "__main__":
app.run(host='0.0.0.0')
========
requirements.txt:
flask
========