How to add several ports to the same Docker container?

0

I am running a docker container running an apache2.4 + PHP7 + MSSQL service the issue is that I want that same container to add port for ssh and ftp, as I would do if I already declared it for the first time the 8080: 80?

    
asked by Saul Montoya 01.02.2018 в 18:46
source

2 answers

1

If you are using a docker-composer file, you can put this, if the container had already been created there are no problems, stop it and then lift it again and add the new ports:

version: '3'
services:
    web:
        image: nginx
        volumes:
            - "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
            - "./etc/ssl:/etc/ssl"
            - "./web:/var/www/html"
            - "./etc/nginx/default.template.conf:/etc/nginx/conf.d/default.template"
        ports:
            - "8080:80"
            - "2222:22"
            - "21:21"
    
answered by 22.02.2018 в 23:31
1

In case you are not using docker-compose and want to call it from terminal with a Docker run, simply use the -p option as many times as necessary.

docker run -p 8080:80 -p X:22 -p Y:21 tu-imagen

You can also use the -P option which is much more powerful, since it will map all the ports that your image has exposed to ports that the host has free (although then you will have to look for them doing a ps docker if you do not have a registrar or similar).

docker run -P tu-imagen

Finally another option is to deploy it directly in the host network so that the exposed ports of the container are directly those of the host, although it is not usually recommended for many reasons (security, abstraction, isolation ...)

docker run --network host tu-imagen

If you want to add them hot with the container running, it probably can not be done, that or that you have to assemble a very important cocoa at the operating system level. My advice is do not do it. Docker works precisely so you do not have to be fond of your containers, or that you are not too lazy to have to load a virtual machine to get it working again. if it stops working or simply (as in your case) you want to add a new fast functionality you load it and then lift it up again.

I hope I have helped you.

    
answered by 30.05.2018 в 10:45