This page looks best with JavaScript enabled

Packaging a Django Development Environment with Docker from Scratch (1) Setting Up the Environment

 ·  ☕ 2 min read

Vagrant is suited to managing virtual machines, while Docker is suited to managing application environments. To better simulate a real runtime environment, this series of articles uses Docker and Docker Compose to build a development environment of Nginx + uWSGI + Django + MySQL + Redis + Rabbit.

1. Basic Concepts

Docker is an open-source application container engine, written in Go and released under the Apache 2.0 license. Docker lets developers package an application together with its dependencies into a lightweight, portable container, and then publish it to a machine.

Docker Compose is a Docker tool for defining and running complex applications.

2. Installing and Using Docker

2.1 Installation

Install Docker on Linux.

1
curl -sSL https://get.daocloud.io/docker | sh

Install Docker Compose on Linux.

1
2
curl -L https://get.daocloud.io/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

2.2 Checking Installation Information

Once installation is complete, you can check whether it succeeded with the following commands.

Check the Docker version.

1
2
docker --version
Docker version 1.12.6, build 88a4867/1.12.6

Check the docker-compose version.

1
2
docker-compose --version
docker-compose version 1.16.1, build 6d1ac21

Start the Docker Daemon. The Docker Client needs to send the commands entered at the console to the Daemon for execution.

1
service docker start

With the docker info command you can see that this machine is using Docker’s native registry mirror.

1
2
3
4
5
6
7
8
docker info // 查看 docker 信息
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
 127.0.0.0/8
Registries: docker.io (secure)

2.3 Pulling and Starting Images

Pull the hello-world image.

1
2
3
4
5
6
docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world

Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f

Start the hello-world image.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Check the local image list.

1
2
3
docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              1815c82652c0        12 weeks ago        1.84 kB

2.4 Configuring a Mirror Accelerator (Optional)

When using Docker you often need to fetch images from the official source, but for network reasons the pull process is very time-consuming, seriously hurting the Docker experience.

The accelerator provided by DaoDlcoud is used here; through intelligent routing and caching it speeds up access to Docker Hub.

1
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://6c5fbccc.m.daocloud.io

3. References


WeChat Official Account
WRITTEN BY
WeChat Official Account