How do I remove the 8000 port from the URL using a Docker container
I configured an app which I added to a docker container and uploaded to a Linode server
After doing docker-compose up --build inside of the Linode server everything seems to work fine except I want to have more control over my urls.
When I enter the URL: 172.234.99.145:8000
it shows me the home page,but what I want to display is only the IP address.
The same goes for my other port which contains the Phpmyadmin image (port 8080) for the database management.
I have tried adding a .conf file and tried manipulating the url's redirect to no success.
What should I do to make the ports not be seen (and possibly replaced with some text like instead of ':8080' to '/phpmyadmin'?
Dockerfile code:
FROM php:7.4-apache
WORKDIR /var/www/html
COPY ./actualapp /var/www/html
RUN apt-get update && \
apt-get install -y curl libpng-dev && \
docker-php-ext-install pdo pdo_mysql gd mysqli
Start Apache when the container runs
CMD ["apache2-foreground"]
docker-compose code:
docker-compose.yml
version: "3"
services:
php-app:
build:
context: .
ports:
- "8000:80"
volumes:
- ./actualapp:/var/www/html
mysql_db:
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "8101:3306"
phpmyadmin:
image: phpmyadmin:latest
environment:
PMA_ARBITRARY: 1
ports:
- "8080:80"
depends_on:
- php-app
- mysql_db
3 Replies
✓ Best Answer
The easiest way to remove the port number from the URL that I've found is setting up a reverse proxy with NGINX. You could then link the server to a domain and use subdomains to point to a specific port/container, rather than using the IP address as the URL. These guides offer two approaches for that.
- Deploy Docker on Akamai Connected Cloud WITH SSL Certification | Reverse Proxy SSL Setup
- How to Expose Services with the Nginx Proxy Manager
You may be able to alter these instructions or find another reverse proxy option that allows you to use the IP address rather than a domain, but hopefully those offer a good starting point.
Thank you for the quick reply!
I will check both of these manuals out.
For future reference for anybody who might encounter a similar issue to mine, what I basically needed at first was for example for 'localhost:8000' to become just 'localhost', I didn't really need to use the port 8000 specifically I just chose it randomly when building my docker container for my app.
Inside the docker-compose.yml file I removed the line
ports:
- "8000:80"
with
ports:
- "80:80"
The solution here is Just using the default 80 port make the port not be seen (when using HTTP of course).
Later on when using different ports the solution above using a reverse proxy and subdomains is useful.