Contribute an article:
Cloud hosts can select operating system images to quickly create a host, which is more convenient than a virtual machine, and we can do this locally because of the Docker thing. It relies on LXC (Linux Container) to get a configured Linux image from the network, and it is very easy to run its own applications in an isolated system. Also because its underlying core is a LXC, you need to run a small LXC in VirtualBox under Mac OS X (here is a Tiny core Linux that runs completely in memory, only about 24MB, with a boot time of less than 5 seconds boot2docker) Virtual machines, built in VirtualBox. The next communication process is docker------boot2docker--and container, port or disk mapping is also in compliance with this relationship.
Understand the above relationship and start talking about the Docker installation process
1. Install VirtualBox, no more speaking, because you want to create a BOOT2DOCKER-VM virtual machine in it
2. Installing Boot2docker
Brew Install Boot2docker
You can also install it manually
Curl Https://raw.github.com/steeve/boot2docker/master/boot2docker > Boot2docker; chmod +x Boot2docker; sudo mv Boot2docker/usr/local/bin
3. Installing Docker
Brew Install Docker
can also be manually installed
Curl-o Docker Http://get.docker.io/builds/Darwin/x86_64/docker-latest; chmod +x Docker; sudo cp Docker/usr/local/bin
4. Configure the Docker client
Export docker_host=tcp://127.0.0.1:4243
Write it down in ~/.bash_profile if you're using bash. I worked under fish, so I added Set-x docker_host to the ~/.config/fish/config.fish tcp://127.0.0.1:4243
5. Boot2docker Initialization and startup
Boot2docker Init
After the completion of the VirtualBox can see a virtual machine called BOOT2DOCKER-VM, and then just use the Boot2docker command to control the behavior of the virtual machine, start, stop and so on.
Boot2docker up
Boot, BOOT2DOCKER-VM virtual machine, we can see the virtual machine become Running state in VirtualBox
Direct execution of Boot2docker can see available parameters
Usage/usr/local/bin/boot2docker {Init|start|up|save|pause|stop|restart|status|info|delete|ssh|download}
6. Start the Docker daemon
sudo docker-d
Then the executable
Boot2docker ssh, enter the password tcuser into the console of the virtual machine, if you want the user name, please enter Docker
The MAC starts with 4243 ports and 4243 ports in the Boot2docker virtual machine, and listens on the/var/run/docker.sock. In this review of the Docker communication process, the Dock command is a 4243-port communication that is opened on the Mac with the Docker daemon, which maps to port 4243 on Boot2docker, and through/var/run/docker.sock communicates with the container therein.
Therefore, if you do not start Docker daemon when you execute Docker version, you will be prompted
2014/05/16 06:52:48 cannot connect to the Docker daemon. Is ' docker-d ' running on this host?
If not started Boot2docker will be prompted
Get http:///var/run/docker.sock/v1.11/version:dial unix/var/run/docker.sock:no such file or directory
Mac OS X--boot2docker--the relationship between container, which is a good illustration of
Photo from: http://tech.uc.cn/?p=2726
The above Boot2docker, Docker is ready, now start to enter the dock operation, there is a command about Docker can see here http://blog.tankywoo.com/docker/2014/05/08/docker- 4-summary.html.
This article original link http://unmi.cc/mac-os-x-experience-docker/, from Yehuang Unmi Blog
1. Download the image and load the boot container
Docker Images #现在没有一个镜像
Docker pull Learn/tutorial #我们把这个拉下来试验 to find all Ubuntu-related images using Docker search Ubuntu
Docker run-i-T learn/tutorial #加载镜像 learn/tutorial to the shell so that it is connected directly to the container, and the container is retired after exiting
Docker PS #在另一个终端中用这个命令, you can see the running instance, which is the container
Now we are on the console of the container [email protected]:/#, can install a apche2, curl and start apache2, to test the next
[Email protected]:/# apt-get Update
[Email protected]:/# apt-get Install apache2 Curl
[Email protected]:/# apachectl Start
[Email protected]:/# Curl http://localhost
<p>this is the default Web page for this server.</p>
<p>the Web server software is running and no content has been added, yet.</p>
</body>
The Apache2 starts normally and is accessible within the container. However, it is not yet possible to access the Apache service from Mac OS X, which requires port mapping in two ways. However, you will need to save the changes to the mirror before port mapping.
2. Save the image
If the previous image is running with Docker run-i-T Learn/tutorial
The software is installed in the container that runs the image, and the new content needs to be saved to the image, or the next time the image is started, it will be restored as it is.
[email protected] ~> Docker ps-l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
95903c1a2bf7 Learn/tutorial:latest/bin/bash 6 minutes ago up 5 minutes 80/tcp Thirsty_colden
See the ID of the container and then execute
Docker commit 95903c1a2bf7 learn/tutorial:latest #把当前容器的修改提交到镜像 learn/tutorial
Running the image again later has the latest installed content.
2. Port mapping
For example, the mapping we're going to do now is Mac OS X (50080)--Boot2docker (40080) and container (80), such as:
Photo Modified from: http://tech.uc.cn/?p=2726
There are two ways to do this.
1)
Boot2docker ssh-l 50080:localhost:40080 is executed #这条命令可以在 the BOOT2DOCKER-VM runtime, creating multiple mappings is performed multiple times
Docker run-i-t-p 40080:80 learn/tutorial
[Email protected]:/# apachectl Start
Then open the http://localhost:50080 in your Mac's browser
2)
Vboxmanage modifyvm "BOOT2DOCKER-VM"--NATPF1 "tcp-port_50080:80,tcp,,50080,,40080"
Docker run-i-t-p 40080:80 learn/tutorial
[Email protected]:/# apachectl Start
This is a direct modification of the BOOT2DOCKER-VM configuration, you can see this configuration in VirtualBox, configure NAT command see Http://www.virtualbox.org/manual/ch06.html#natforward. Many port mappings can also be established.
You can also edit the port mapping relationship directly here
The world of Docker is wonderful, and the rest is basically how to use Docker commands, such as managing images, containers, and creating your own images; Docker has three ways to run commands, short-term, interactive, daemon way; Use SSH to manage containers and so on.
In addition to using Boot2docker as a LXC, there is also a substitute for the use of Docker under Mac VAGRANT.
Reference:
1. Building a development environment with Docker
2. One of the Docker learning notes to build a Java Tomcat runtime environment
3. Installing Docker on Mac OS X
4. Https://github.com/boot2docker/boot2docker
5. Docker Quick Start
Docker on Mac