MCPcopy
hub / github.com/twtrubiks/docker-tutorial

github.com/twtrubiks/docker-tutorial @main sqlite

repository ↗ · DeepWiki ↗
11 symbols 55 edges 13 files 1 documented · 9%
README

docker-tutorial

中文版

Docker Beginners Guide - From Scratch

Learn how to use Docker to build Django + PostgreSQL 📝

Other Information

Introduction

Docker

Containers as a Service (CaaS)

This technology has become popular in recent years, and many companies use Docker. It's really convenient and worth learning about. :smile:

If you have problems with inconsistent environments, use Docker! :smile:

If you're driven crazy every time you set up an environment, use Docker! :blush:

If you want a high-efficiency, lightweight environment that starts in seconds, use Docker! :blush:

If you don't want to drive yourself crazy, use Docker! :smile:

If you want to be super cool, you must use Docker! :laughing:

What is Docker?

Docker is an open-source project that appeared in early 2013, initially as a side project within Dotcloud.

It is implemented in the Go language, which was launched by Google. (Dotcloud later changed its name to Docker).

We won't go into the technical principles here, but let's briefly mention its benefits.

First, let's look at the official website's explanation:

Comparing Containers and Virtual Machines

From this diagram, you can see that Containers do not have an OS, so they are naturally smaller in size and start up incredibly fast.

For details, see https://www.docker.com/what-container

What are Virtual Machines?

Similar to https://www.virtualbox.org/, we might use it to install other operating systems. For example,

I'm on a MAC, but I want to use Windows, so I'll install a VM on my MAC and install the Windows system.

A table to understand how great Docker is :+1:

Feature Containers Virtual Machines (Traditional Virtualization)
Startup Seconds Minutes at best
Size MB GB
Performance Fast Slow
Number Supported Many Containers A dozen is a lot
Replicating Environment Fast Very Slow

Don't get it? :question: :question: :question:

Let's look at a diagram, I guarantee you'll understand.

Image source: https://blog.jayway.com/2015/03/21/a-not-very-short-introduction-to-docker/

Why use Docker?

It's cool~ No explanation needed :satisfied:

More efficient use of resources

Compared to something like https://www.virtualbox.org/, Docker has higher utilization. We can set up more

Containers, and they start up incredibly fast! :flushed:

Unified environment

I believe everyone has had the frustrating experience of setting up a computer environment. :angry:

If a new colleague joins the company, you have to set up the environment for them all over again. :expressionless:

Or, "It runs fine on my machine~ Why doesn't it work on yours? Is it because of version xxx?" :joy:

I believe everyone has more or less encountered these situations. We can solve these problems with Docker,

keeping everyone's environment consistent, and it's fast to set up. :smile:

Benefits for DevOps

For DevOps, the ideal scenario is to configure once and be able to quickly set up the environment and run it correctly anywhere in the future.

Docker Concepts

It's recommended to first understand a few terms in Docker:

Image

An image can be thought of as the Guest OS we used to play with in VMs (the operating system installed on a virtual machine).

Images are read-only (R/O).

Container

A container is created from an image. One image can create multiple different containers.

Containers can be started, begun, stopped, deleted, and are isolated from each other.

When a container starts, it creates a read-write (R/W) layer on the outermost (top) layer.

This diagram explains the relationship between read-only (R/O) images and read-write (R/W) containers.

For more on this relationship, see https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers/#images-and-layers

Registry

You can think of it as something like GitHub, which stores a large number of images. You can browse them on Docker Hub.

I won't explain in more detail here, I'll leave it for you to do your homework. :stuck_out_tongue:

Installation

Windows

First, go to the official Docker website

https://www.docker.com/docker-windows

Download the stable version

Next is a straightforward installation. After installation, it will ask you to log out of your computer. Click it and it will log you out.

Then, if your computer does not have Hyper-V enabled, it will ask you to restart your computer. (Again, just click it)

(For more information on Hyper-V, see https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/about/)

After restarting, you will see the cute Docker icon pop up in the bottom right corner.

We can use cmd to confirm if the installation was successful.

docker --version
docker-compose --version

Remember to set up one more thing: Shared Drives

After installation, it is recommended to install Kitematic as well. It has a GUI interface, which makes it easier to use Docker.

(Later, I will introduce an even better GUI interface, portainer :grin:)

I know typing commands is cool, but it's still recommended to install it.

Right-click on your Docker icon, and you will see Kitematic.

Download, unzip, and double-click to use.

MAC

I also have a MAC, but since I installed it a long time ago, I didn't record the steps. It's basically the same.

https://www.docker.com/docker-mac

Linux

Youtube Tutorial - How to install Docker on Ubuntu (Linux)

Here we use Ubuntu as an example.

Although you can install docker very quickly in ubuntu using snap,

we will not use the snap method here. :smile:

Please follow the official documentation for installation steps.

Get Docker Engine - Community for Ubuntu

Get Docker Engine - Community for Ubuntu

Post-installation steps (optional :exclamation:), but it is recommended to take a look.

Post-installation steps for Linux

docker-compose installation

docker-compose install

System resource allocation issue,

If you are using docker for windows or mac,

you will have an interface to set how much cpu and ram you want to allocate to your docker,

usually in Preferences -> Advanced, there is a GUI interface,

But if you are using linux, there will be no such interface, because in Linux,

resources will be allocated automatically according to the system's resources.

Command Introduction

Next, let's introduce some Docker commands.

There are really a lot of Docker commands, so here I will only introduce the ones I use more often or find more practical.

View current images

docker images

Create an image

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

For detailed parameters, see https://docs.docker.com/engine/reference/commandline/create/

Example (create an image named busybox)

docker create -it --name busybox busybox

Delete an Image

docker rmi [OPTIONS] IMAGE [IMAGE...]

View currently running containers

docker ps

View all containers (including stopped ones)

docker ps -a

Create and start a Container

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

For example

docker run -d -p 80:80 --name my_image nginx

-d means run in Detached (background) mode. If -d is not added, it will run in the foreground by default.

-p means forward all traffic from port 80 of the host to port 80 of the container.

--name sets the name of the container.

Another example

 docker run -it --rm busybox

--rm means that when you exit the container, the container will be automatically removed. (incompatible with -d)

For more details, see https://docs.docker.com/engine/reference/run/

Start a Container

docker start [OPTIONS] CONTAINER [CONTAINER...]

If you want to run it in the foreground and watch the output, you can use the following command

docker start -a [OPTIONS] CONTAINER [CONTAINER...]

--attach or -a means Attach STDOUT/STDERR and forward signals.

For more details, see https://docs.docker.com/engine/reference/commandline/start/

(You only need to write a few characters of the container ID, the concept is the same as Git.

If you don't understand Git, you can refer to Git-Tutorials GIT Basic Usage Tutorial)

Stop a Container

docker stop [OPTIONS] CONTAINER [CONTAINER...]

Restart a Container

docker restart [OPTIONS] CONTAINER [CONTAINER...]

Delete a Container

docker rm [OPTIONS] CONTAINER [CONTAINER...]

--volumes , -v Adding this parameter will remove the volumes associated with this container.

See https://docs.docker.com/engine/reference/commandline/rm/

Enter a Container

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
docker exec -it <Container ID> bash

Enter as root user

docker exec -u 0 -it <Container ID> bash
docker exec -u root -it <Container ID> bash

Typing comma

Core symbols most depended-on inside this repo

main
called by 1
api/manage.py
detail_action
called by 0
api/musics/views.py
all_singer
called by 0
api/musics/views.py

Shape

Class 6
Method 2
Route 2
Function 1

Languages

Python100%

Modules by API surface

api/musics/views.py5 symbols
api/musics/serializers.py2 symbols
api/musics/models.py2 symbols
api/musics/apps.py1 symbols
api/manage.py1 symbols

Dependencies from manifests, versioned

Django3.2.8 · 1×
djangorestframework3.12.4 · 1×
psycopg22.9.1 · 1×

For agents

$ claude mcp add docker-tutorial \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact