Search code examples
cloud-foundrypcfdev

Cloud Foundry alternative for 'docker run --add-host'


If I want to add an entry in the /etc/hosts file of a container, in Docker, I can use following command:

docker run --add-host foo:10.0.0.3 myimage

If I want to do the same in Pivotal Cloud Foundry application, how do I do it?


Solution

  • If you're using a buildpack to deploy your application then you cannot. Applications deployed via buildpack run as the vcap user and do not have root access, so you cannot edit /etc/hosts.

    If you're using Docker to deploy your application on CloudFoundry, you could modify the /etc/hosts file in your image and that would persist through to your application when it runs on CF. That said, I don't know of any way to do this dynamically as you run the image like the command you referenced above.