I'm trying to setup a SonarQube container backed by a MySQL database container. My docker-compose.yml:
sonar:
environment:
- SONARQUBE_USER=sonar
- SONARQUBE_PASSWORD=sonar
- SONARQUBE_DATABASE=sonar
- SONARQUBE_JDBC_URL=jdbc:mysql://db:3306/sonar?useUnicode=true&characterEncoding=utf8
build: .
ports:
- "19000:9000"
- "19306:3306"
links:
- db
db:
environment:
- MYSQL_ROOT_PASSWORD=root-secret
- MYSQL_USER=sonar
- MYSQL_PASSWORD=sonar
- MYSQL_DATABASE=sonar
image: mysql
In the ports
section I'm trying to expose both port 9000 from SonarQube (web interface) and port 3306 (MySQL connection).
Is there any way to expose a port from a linked service (such as db
in this case) from the "main" container e.g. sonar
?
EDIT: Just to better explain my needs, I want to expose both ports to my localhost
. I need access to both ports from my machine, as I SonarQube runner needs access to the database and I want to run some queries in the database too, from my machine, not inside another container.
You don't need to: an EXPOSE
port from one service is directly visible from another (linking to the first).
No port mapping necessary (as you do for 9000 from SonarQube and 3306)
Port mapping is necessary for accessing a container from the host.
But from container to a (linked) container (both managed by the same docker daemon), any port declared in EXPOSE
in its Dockerfile
is directly accessible.
I want to expose both ports to my localhost. I need access to both ports from my machine, as I SonarQube runner needs access to the database
Well then,... the db
section should have its own port mapping section:
db:
ports:
- "xxx:yyyy"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With