Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

285
Views
When to use --hostname in docker?

Is --hostname like a domain name system in docker container environment that can replace --ip when referring to other container?

8 months ago · Santiago Trujillo
3 answers
Answer question

0

The --hostname flag only changes the hostname inside your container. This may be needed if your application expects a specific value for the hostname. It does not change DNS outside of docker, nor does it change the networking isolation, so it will not allow others to connect to the container with that name.

You can use the container name or the container's (short, 12 character) id to connect from container to container with docker's embedded dns as long as you have both containers on the same network and that network is not the default bridge.

8 months ago · Santiago Trujillo Report

0

--hostname is a parameter which can be given along with docker run command which will set the specified name as containers hostname whereas --ip is parameter to set specific ip address(ipv4) to that particular container.

docker run --hostname test --ip 10.1.2.3 ubuntu:14.04 

The following command will create a docker container with base image as ubuntu-14.04 with hostname as test and container ip address as 10.1.2.3

8 months ago · Santiago Trujillo Report

0

If you need to change the hostname in a way that other containers from the same network will see it, just use --net-alias=${MY_NEW_DNS_NAME}

For example:

docker run -d --net-alias=${MY_NEW_DNS_NAME} --net=my-test-env --name=my-docker-name-test <dokcer-contanier>

Please see: Difference between --link and --alias in overlay docker network?

8 months ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.