Under Linux We can create a new container in Docker and then direct access to the container via port forwarding. But in the middle of the Mac, it passed.
A layer of virtual machines, so port forwarding needs to be done a little more.
1 connect the local port to the virtual machine: You can do it by command:
"boot2docker-vm""containerssh,tcp,,2222,,2222"
You can also add by hand:
Click Port forwarding to Add.
2 Create a container based on the image, map the virtual machine to 2222 ports to 22, and open the SSH service
? ~ dockerrun-ti-p 2222:22sshd:ubuntu2
To open the SSH service:
? ~ Docker Start-i theRoot@886ab361140c:/# ssh localhostSSH:Connect to host localhost port A: ConnectionRefusedroot@886ab361140c:/# service SSH start*starting OpenBSD Secure ShellServer sshd [OK]root@886ab361140c:/#
3 SSH links to the container on the host:
? ~ SSH [email protected]127.0. 0. 1-P2222Warning:permanently added' [127.0.0.1]:2222 '(RSA) to theList ofKnown hosts. Welcome toUbuntu14.04. 2LTS (Gnu/linux4.0. 3-boot2docker x86_64) * Documentation:HTTPS://help.ubuntu.com/last login:tue June9 Geneva: A: $ - from 10.0. 2. 2[Email protected]886ab361140c:~#
Just don't know why wait here for a while before connecting.
Finally, the port mapping is successful, you can do all kinds of things in the container, such as Nginx,apache, database and so on, and access outside the container.
4 configuration of Virtual machine network
In addition, if you are using a virtual machine to create a new Linux: How to make Linux in the virtual machine can access the extranet and can be accessed by the external network:
Virtual machine in the Linux to access the external network is through the bridge to the outside network implementation, outside the host to access to the virtual machine Linux is through the host-only way.
So the NIC part needs to configure two network cards:
Port forwarding for Docker under Mac