Port forwarding for Docker under Mac

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.