I'm using docker in a windows environment using docker toolbox how could I make an example database access available in a container on my local network. What kind of settings should I perform in order to have this access?
I'm using docker in a windows environment using docker toolbox how could I make an example database access available in a container on my local network. What kind of settings should I perform in order to have this access?
I'll use a postgres container as an example. Consider this Dockerfile
where create.sql
is a SQL script for creating database tables:
FROM postgres:latest
ENV POSTGRES_DB atividade-dac
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD postgres
COPY create.sql /docker-entrypoint-initdb.
Now creating the image and running the container:
docker build -t meuBanco .
docker run -p 5432:5432 --name host-banco -d meuBanco
The -p 5432:5432
command maps the port of my machine (where the container is running) to the container port (port binding). This means that when accessing the 5432
port on my machine the client will be redirected (transparently) to the container so from this moment on, for any client it is as if the database was running directly on my machine rather than running in a container.
With this in mind to limit access to this container only your local network just create some rules in your firewall that limit access to the machine on which the container is running (in this example, limiting access to port 5432
).