Moose
Moose

Reputation: 1317

Is it possible to have a custom url for a docker container?

I have the following Dockerfile and was wondering what I would need to do in order to get access to it from my host machine by visiting myapp.dev:

FROM ubuntu:16.04

USER root

RUN apt-get update && apt-get -y upgrade && apt-get install apt-utils -y && DEBIAN_FRONTEND=noninteractive apt-get -y install \
    apache2 php7.0 php7.0-mysql libapache2-mod-php7.0 curl lynx-cur git

EXPOSE 80

ADD www /var/www/site

RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

CMD /usr/sbin/apache2ctl -D FOREGROUND

EXPOSE 80

I am using the following command to run the container:

docker run -d -p 8080:80

Upvotes: 3

Views: 6771

Answers (1)

Sebastian
Sebastian

Reputation: 17413

If you only want to be able to resolve it locally you could add an alias for localhost in your hosts file.

  1. Locate your hosts file.
    • Linux: /etc/hosts
    • MacOS: /private/etc/hosts
    • Windows: C:\Windows\System32\drivers\etc\hosts
  2. Add this line at the end of the file:

    127.0.0.1 myapp.dev
    

Now you can access your container using myapp.dev:8080.

Upvotes: 5

Related Questions