docker run -it ubuntu:latestĪpt-get update & apt-get install -y psql -user postgres -host We’ll start by running an Ubuntu docker image in interactive mode and installing the postgres command line tools. I have a table Users in database bernieslearnings and I’ll run a container that can retrieve the data in the table. For the PostgreSQL installation, I have installed the default settings and haven’t edited any configuration files to perform the following tasks. I’ll use a PostgreSQL installation local on my Mac to demonstrate. A practical use case to connect docker to localhostĪ typical example of using a connection to localhost is connecting to a database you have installed locally. For Linux users, just use docker run with –network=”host” and use 127.0.0.1 to point to your localhost. So only use this in your development environment. This will not work in a production environment outside of Docker Desktop. Within your container, all you need to do to access the localhost is point your request to : To connect Docker to localhost, running Docker for Windows or Docker for Mac, you can use the special DNS name which resolves to the internal IP address used by the host.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |