Lecture Notes 1.2.2 (Containers and Shell, Creating Docker Images, Backing Up a Docker Container)
Lecture Notes 1.2.2 (Containers and Shell, Creating Docker Images, Backing Up a Docker Container)
2
Containers and Shell
Containers are isolated environments in which applications can run. They include the
application and its dependencies but share the host system's kernel.
1. Create a Dockerfile: A Dockerfile is a text document that contains instructions for building a Docker image.
Dockerfile
* Use an official Python runtime as a parent image
FROM python:3.8-slim
* Set the working directory in the container
WORKDIR /app
* Copy the current directory contents into the container at /app
COPY . /app
* Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
* Make port 80 available to the world outside this container
EXPOSE 80
* Define environment variable
ENV NAME World
* Run app.py when the container launches
CMD ["python", "app.py"]
2. Build the image:
docker build -t my-python-app .
3. Run the container:
docker run -p 4000:80 my-python-app
Backing Up a Docker Container
· Preserve State: Save the current state of a container, including all data and
configuration changes.
· Migration: Move the container to a different host or environment without losing its
state.
Backing Up a Docker Container
Video Links:
https://youtu.be/Gjnup-PuquQ
https://youtu.be/wi-MGFhrad0
https://youtu.be/a1M_thDTqmU
Textbooks:
1. Matthias, Karl, and Sean P. Kane. Docker: Up and Running. 2nd ed., O'Reilly Media, 2018.
2. Bullington-McGuire, Richard, Andrew K. Dennis, and Michael Schwartz. Docker for Developers: Develop and Run Your
Application with Docker Containers. 1st ed., Apress, 2019.
Reference Books:
3. Turnbull, James. The Docker Book: Containerization is the New Virtualization. 1st ed., James Turnbull, 2014.
4. Freeman, Emily. DevOps for Dummies. 1st ed., For Dummies (Wiley), 2019.
Web Links:
• Docker Documentation
• Docker Tutorial
9
THANK YOU
10