Connecting to the Host Networkĭocker provides a host network which lets containers share your host’s networking stack. You could replace with your own string if you prefer. The value shown above maps to the container’s host gateway, which matches the real localhost value. The -add-host flag adds an entry to the container’s /etc/hosts file. Start your containers with this flag to expose the host string: docker run -d -add-host :host-gateway my-container:latest This is the simplest technique when you’re working on a Windows or Mac machine.ĭocker Engine users on Linux can enable too via the -add-host flag for docker run. If you’re running a MySQL server on your host, Docker containers could access it by connecting to :3306. localhost and 127.0.0.1 – These resolve to the container.Use this string inside your containers to access your host machine. The Easy Optionĭocker Desktop 18.03+ for Windows and Mac supports as a functioning alias for localhost. Here’s how to access localhost or 127.0.0.1 from within a Docker container. Sometimes you might need a container to talk to a service on your host that hasn’t been containerized. When working with Docker, you usually containerize the services that form your stack and use inter-container networking to communicate between them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |