Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use boot2docker to manage docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use boot2docker to manage docker". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

To use Docker on Mac, you need to use boot2docker to establish a virtual machine hosting environment where docker runs. Installing boot2docker can be easily installed through brew.

Brew install boot2docker

# start boot2docker

After a successful installation, start docker in the following ways

Boot2docker init

The above command only needs to be executed once, and it creates the virtual machine environment needed for Docker to run. When running in the future, you need to start the docker virtual machine first.

Boot2docker start

This starts the virtual machine environment of Docker and uses the command boot2docker shellinit to view the environment variables of the Docker client

$boot2docker shellinitWriting / Users/mylxsw/.boot2docker/certs/boot2docker-vm/ca.pemWriting / Users/mylxsw/.boot2docker/certs/boot2docker-vm/cert.pemWriting / Users/mylxsw/.boot2docker/certs/boot2docker-vm/key.pem export DOCKER_HOST=tcp://192.168.59.103:2376 export DOCKER_CERT_PATH=/Users/mylxsw/.boot2docker/certs/boot2docker-vm export DOCKER_TLS_VERIFY=1

You can manually execute the last three export commands of the output to set the environment variables, or you can use the following methods to set the environment variables automatically

$eval "$(boot2docker shellinit)"

So far, boot2docker is running, and the client environment for docker has been established. To verify success, run the following command

$boot2docker statusrunning$ docker versionClient version: 1.3.2Client API version: 1.15Go version (client): go1.3.3Git commit (client): 39fa2faOS/Arch (client): darwin/amd64Server version: 1.6.2Server API version: 1.18Go version (server): go1.4.2Git commit (server): 7c8fca2

Use the command boot2docker ssh:

If an error like dial unix / var/run/docker.sock: no such file or directory occurs when executing the docker command because the correct environment variable is not set, execute the command eval "$(boot2docker shellinit)" to reset the environment variable.

# basic Operation

Start a Nginx container on DOCKER_HOST

$docker run-d-P-- name web nginx

In the above command, the docker run command starts a container run and then exits, and the-d option specifies that the container docker run command runs in the background after the execution is complete. The-P option exposes the open ports of the container to the host so that we can access them.

To see which containers are currently running, use the docker ps command

To see which ports are open for the container, use the command docker port

$docker port web443/tcp-> 0.0.0.0:3276980/tcp-> 0.0.0.0purl 32768

Next, visit 127.0.0.1 32768, and you should see the welcome page of Nginx.

Under Mac, it is not possible to access 127.0.0.1 when using boot2docker, because the host of docker is a virtual machine of boot2docker, so you need to use the ip of the virtual machine to access boot2docker ip to obtain ip.

You can visit 192.168.59.103vig 32768.

To stop or delete a running container, use the following command

$docker stop web$ docker rm web

To close boot2docker, use the command boot2docker stop.

# Mount volumes in Container

When boot2docker is started, it automatically shares the / Users directory on the Mac on the virtual machine, and in the Docker container, the contents of this directory can be mounted into the Docker container.

Docker@boot2docker:~$ ll / Users/total 0drwxr-xr-x 1 docker staff 374 Dec 4 08:42 Guest/drwxrwxrwx 1 docker staff 306 Apr 10 16:19 Shared/drwxr-xr-x 1 docker staff 2890 May 19 09:32 mylxsw/

Create the site/index.hml file in the Downloads directory of Mac, as follows

$pwd/Users/mylxsw/Downloads$ tree. └── site └── index.html1 directory, 1 file$ cat site/index.htmlmy new site: aicode.cc

Start the docker container

$docker run-d-P-v $HOME/Downloads/site:/usr/share/nginx/html-- name mysite nginx3ec8c748b423b9ff30efaab6e4c88857c45831cca8a46e97950808635c2dd98d$ docker port mysite443/tcp-> 0.0.0.0:3277080/tcp-> 0.0.0.0 name mysite nginx3ec8c748b423b9ff30efaab6e4c88857c45831cca8a46e97950808635c2dd98d$ docker port mysite443/tcp 32771 $boot2docker ipThe VM's Host only interface IP address is: 192.168.59.103

The-v parameter of docker run specifies the volume to be mounted, or you can use-- volume in the format-v / host:/container.

Visit http://192.168.59.103:32771/ to see the contents of the output index.html

$curl http://192.168.59.103:32771/my new site: aicode.cc "how to use boot2docker to manage docker" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report