Mounting
Volumes
Docker manage the mount points and data.
Use it if want to store your container’s data on a remote host and not locally.
Bind (need it here)
Use it if you want to save your data locally on the host itself or want to share data from your Docker host to the Docker container especially, configuration files, source code, etc.
tmpfs (not relevant here)
Best for sensitive data or information, you do not want the data to be saved on the host machine or docker container (store secret keys for an example)
Data does not persist in container (run)
Create container, create file and write a random number to it.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
834744ade459 ubuntu "bash -c 'shuf -i 1-…" 3 minutes ago Up 3 minutes silly_clarke
Read data.txt content
8072
Delete container and create from the same image a new one
Result:
bin dev home lib32 libx32 mnt proc run srv tmp var
boot etc lib lib64 media opt root sbin sys usr
Create Docker file
Create image getting-started
Create new image
Create and run container from getting-started
See intial code
Create and run container from getting-started1
See changed code
- Keep versions of code in container image.
- Keep data in container volumes, see next.
Persist data between runs
By default, the todo app stores its data in a SQLite database at /etc/todos/todo.db in the container’s filesystem
With the database being a single file, if we can persist that file on the host and make it available to the next container, it should be able to pick up where the last one left off.
docker volume create persistent-data-db
docker run -dp 3000:3000 --mount type=volume,src=persistent-data-db,target=/etc/todos getting-started
Stop & delete getting-started container
--network todo-app --network-alias mysql `
-v todo-mysql-data:/var/lib/mysql `
-e MYSQL_ROOT_PASSWORD=secret `
-e MYSQL_DATABASE=todos `
mysql:8.0
Allows to create multiple containers and the environment. Manage all from a file.
You may say infrastructure as code at small scale in this case.
Same git source like above.
in /app create a file docker-compose.yml
When run, this will create 3
Run
All you change in codes source locally reflect into app container immediately (on reload)
To see database / tables:
bash-4.4# mysql -u root -p
Shut it down:
Containers are stopped and deleted
Images stay.
Volume with data stay
Create & start images.
CI/CD pipe
Terms
1. venv
Creation of virtual environments — Python 3.11.1 documentation
The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in theirsite directories. A virtual environment is created on top of an existing Python installation, known as the virtual environment’s “base” Python, and may optionally be isolated from the packages in the base environment, so only those explicitly installed in the virtual environment are available.
When used from within a virtual environment, common installation tools such aspip will install Python packages into a virtual environment without needing to be told to do so explicitly.
2. PEP 405
Python Virtual Environments
This PEP proposes to add to Python a mechanism for lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (allowing creation of environments with various Python versions) and can have its own independent set of installed Python packages in its site directories but shares the standard library with the base installed Python.
Create a flask web server container
Tag it and check
ok
Create data volumes and network
That's all here
Push all on GitHub
1. Create a new GitHub repository using this template repository.
Settings, and go to Secrets > Actions.
Create a new secret named DOCKERHUB_USERNAME and your Docker ID (your username, see it top right) as value.
Copy Access Token
When logging in from your Docker CLI client, use this token as a password.
ACCESS TOKEN DESCRIPTION
clockboxci
ACCESS PERMISSIONS
Read, Write, Delete
To use the access token from your Docker CLI client:
1. Run docker login -u <YOUR_DOCKER_ID>
2. At the password prompt, enter the personal access token.
<GENERATED_PASSWORD>
WARNING: This access token will only be displayed once. It will not be stored and cannot be retrieved. Please be sure to save it now.
Commit.
When finish you will have all done in Docker (repository just creatde)
Deploy docker container to Azure
In VS code.
1.Subscription you will use:
<AZURE_SUBSCRIPTIO_ID>
Location
<AZURE_LOCATION>
For East US you will write eastus
Resource group. Create it before starting. Cost nothing if nothing in it.
<AZURE_RESOURCE_GROUP>
Context name, name it whatever you wish - be it: docker-context-eastus
In VS Code terminal:
Run (create) in Azure (you are in Azure context)
Result:
pensive-kowalevski - registry.hub.docker.com/library/nginx - Running 20.241.142.42:80->80/tcp
IP is wat I need:
Load in browser:
http:// 20.241.142.42:80
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer tonginx.org.
Commercial support is available atnginx.com.
REMOVE IT FROM AZURE - it starts changing your CC
Delete resource group if there is nothing in it except this container.
List contexts
Result:
https://kubernetes.docker.internal:6443 (default) - swarm
desktop-linux moby - npipe:////./pipe/dockerDesktopLinuxEngine
docker-context-eastus - aci - <AZURE_RESOURCE_GROUP>@<AZURE_LOCATION>
Last line is what I was looking for.
Set default context back, otherwise I will not have access to any of my local dockercontainers.
You have all you need so far. Let you imagination wild or learn Azure DevOps from Microsoft.
Containers basis, Login to view
Docker basis, Login to view
References
Best practices for writing Dockerfiles | Docker Documentation
Docker development best practices | Docker Documentation
BuildKit | Docker Documentation
Documentation | Node.js (nodejs.org)
3.11.1 Documentation (python.org)
How Kubernetes works under the hood with Docker Desktop | Docker
venv — Creation of virtual environments — Python 3.11.1 documentation
PEP 405 – Python Virtual Environments | peps.python.org
