John David

John David

1548831533

Docker-compose and Postgres : Name does not resolve

In docker, I am trying to configure Postgres, get it up and running in another container, and link it to my users service, set up with the following structure:

docker-compose-dev.yml
services/
        users/
             manage.py
             Dockerfile-dev
             entrypoint.sh
             project/
                    __init__.py
                    db/
                      create.sql
                      Dockerfile

docker-compose-dev.yml

version: '3.7'

services:

users:
build:
context: ./services/users
dockerfile: Dockerfile-dev
volumes:
- ‘./services/users:/usr/src/app’
ports:
- 5001:5000
environment:
- FLASK_APP=project/init.py
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev
- DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test
depends_on:
- users-db

users-db:
build:
context: ./services/users/project/db
dockerfile: Dockerfile
ports:
- 5435:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres

Dockerfile-dev

# base image
FROM python:3.7.2-alpine

install dependencies

RUN apk update &&
apk add --virtual build-deps gcc python-dev musl-dev &&
apk add postgresql-dev &&
apk add netcat-openbsd

set working directory

WORKDIR /usr/src/app

add and install requirements

COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

add entrypoint.sh

COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh

add app

COPY . /usr/src/app

run server

CMD [“/usr/src/app/entrypoint.sh”]

Here I try to extend the official Postgres image by adding a SQL file to the “docker-entrypoint-initdb.d” directory in the container.

Dockerfile

# base image
FROM postgres:11.1-alpine

run create.sql on init

ADD create.sql /docker-entrypoint-initdb.d

create.sql

CREATE DATABASE users_prod;
CREATE DATABASE users_dev;
CREATE DATABASE users_test;

Since the “users” service is dependent not only on the container being up and running but also the actual Postgres instance being up and healthy, I added an entrypoint.sh file to “users”:

entrypoint.sh

#!/bin/sh

echo “Waiting for postgres…”

while ! nc -z users-db 5432; do
sleep 0.1
done

echo “PostgreSQL started”

python manage.py run -h 0.0.0.0

manage.py

from flask.cli import FlaskGroup
from project import app, db

cli = FlaskGroup(app)
@cli.command(‘recreate_db’)
def recreate_db():
db.drop_all()
db.create_all()
db.session.commit()
if name == ‘main’:
cli()

I run and sucessfully build it with:

docker-compose -f docker-compose-dev.yml up -d --build

but Im having some network issue. If i run:

docker-compose -f docker-compose-dev.yml logs

I get:

Attaching to dev2_users_1
users_1 | Waiting for postgres…
users_1 | nc: getaddrinfo: Name does not resolve
users_1 | nc: getaddrinfo: Name does not resolve
users_1 | nc: getaddrinfo: Name does not resolve
users_1 | nc: getaddrinfo: Name does not resolve
users_1 | nc: getaddrinfo: Name does not resolve
(…)

Can somebody please point me in the right direction here? What am I missing in the code above?

#docker #postgresql

What is GEEK

Buddha Community

Valerio Tana

1548832679

Looks like you haven’t taken care of docker networking, by default it runs in bridge mode. :)

Iliana  Welch

Iliana Welch

1595249460

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub

In this video lesson you will learn:

  • What is Docker Host
  • What is Docker Engine
  • Learn about Docker Architecture
  • Learn about Docker client and Docker Daemon
  • Docker Hub and Registries
  • Simple demo to understand using images from registries

#docker #docker hub #docker host #docker engine #docker architecture #api

Paris  Turcotte

Paris Turcotte

1617952320

Creating and filling a Postgres DB with Docker compose

Many times we need to populate and eventually share a database with dummy data, either to test our pipelines, test queries, make a demo of the operation of a new service, or perhaps as a tool to apply testing to the future members of the company.

_Github repo: _https://github.com/jdaarevalo/docker_postgres_with_data

Introduction

Among the various options that we have to solve this requirement is to use or share files such as CSV, parquet, s3, among others, but those have limitations in each of the challenges that we want to face.

This is a problem that can be solved easily by making use of the features that Docker offers to us.

Our goal here will be to create the following tables with their respective foreign keys and fill the tables, while they can be easily shared with other users.

#postgres #docker-compose #fill-tables #docker #postgresql

August  Murray

August Murray

1615008840

Top 24 Docker Commands Explained with Examples

In my previous blog post, I have explained in detail how you can Install Docker and Docker-compose on Ubuntu

In this guide, I have explained the Top 24 Docker Commands with examples.

Make sure you have sudo or root privileges to the system.

Docker Commands

  1. The command to check the version of Docker installed.
  2. To look/search for available docker images from the Docker registry.
  3. To pull docker images from the Docker registry.
  4. Listing all the docker images
  5. Creating / Running docker container from Docker image.
  6. To list the actively running docker containers.
  7. To list all the docker containers
  8. To stop a Container
  9. To start a Container
  10. To restart a Docker container
  11. To login to running Docker container
  12. To delete the stopped Docker containers
  13. To delete Docker images from the Local system
  14. To check logs of a running Docker container
  15. Killing docker containers
  16. Log in to Docker Hub registry (hub.docker.com)
  17. Removing docker hub registry login from the system.
  18. Check active resource usage by each containers
  19. Rename a Docker container
  20. To display system wide information of Docker
  21. Inspecting a Docker container
  22. Building docker images from Docker file
  23. Creating new docker images from a Container
  24. Pushing Docker images from Local to Docker registry.

#docker #docker-command #containers #docker-compose #docker-image

Loma  Baumbach

Loma Baumbach

1600358785

Deploy a Tomcat Application Using Docker-Compose

In this blog, we will learn what is docker-compose and how we can deploy a tomcat application which uses mysql database. We will learn how we can setup a development environment using docker-compose in a single command

Prerequisite:

  1. Docker and Docker-compose installed

INTRODUCTION

  • Docker-compose is a tool which is used to deploy multi-container application.
  • One single yaml file to deploy your application on the server.
  • Best suited for the developers to setup their workstation in a single command without installing any kind of dependencies for the application
  • docker-compose up to start your application
  • docker-compose down to clean up all the docker containers

Let’s take an example here:

We have a project called user registration which uses mysql for storing the data . In terms of microservices, we can say that we have two services as shown below:

  • Web Service
  • Database Service

You can clone this git repo and try the below example

Explanation of docker-compose

  1. **version : **This is the version as per the docker engine you have installed on your machine
  2. **services: **This is the main tag which is used to configure multiple services and under that we have details of all the services

3. web: This is our service name -> using image, ports and volumes

4. **volumes: **To store the database files

Now we will create main docker-compose file which will together launch a tomcat, mysql and phpmyadmin container

Tomcat container — To run your application

**Database container **— To store the data

PhpMyAdmin — Access the database through GUI

So we will have three services

  1. db — we are using local path to store the data so that when you run docker-compose down all your data will retain. If you use the volume then all data will get lost if you run the docker-compose down

Also, we are importing sql file so that our database is ready with the sample data. It is good so that each developer will always have the base or the actual data to run their application on the local machine

2. phpmyadmin — which is used to access the database through GUI and it depends on service db

3. web — which is used to access your web application and it also depends on service db

version: '3.3'
services:
   db:
     image: mysql:5.7
     volumes:
       - /opt/test:/var/lib/mysql
       - ./mysql-dump:/docker-entrypoint-initdb.d
     environment:
       MYSQL_ROOT_PASSWORD: root
       MYSQL_DATABASE: testdb1
       MYSQL_USER: testuser
       MYSQL_PASSWORD: root
     ports:
       - 3306:3306
phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    ports:
      - '8081:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: root
web:
    depends_on:
      - db
    image: tomcat
    volumes:
      - ./target/LoginWebApp-1.war:/usr/local/tomcat/webapps/LoginWebApp-1.war
    ports:
      - '8082:8080'
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: testdb1
      MYSQL_USER: testuser
      MYSQL_PASSWORD: root

#docker-compose #docker-image #docker

Cómo instalar Drupal con Docker Compose

Введение

Docker позволяет легко помещать приложения и службы в контейнеры, чтобы их можно было запускать где угодно. Однако при работе с Docker можно легко накопить чрезмерное количество неиспользуемых образов, контейнеров и томов данных, замедляющих работу и потребляющих место на диске.

Docker предоставляет все необходимые инструменты для очистки системы из командной строки. В этом руководстве с полезными советами кратко описываются полезные команды для освобождения места на диске и организации системы посредством удаления неиспользуемых образов, контейнеров и томов Docker.

Использование этого руководства:

  • Это руководство в формате полезных советов содержит автономные сниппеты для командной строки
  • Вы можете перейти к любому разделу, актуальному для задачи, которую вы пытаетесь выполнить.

Синтаксис замены команды command $(``command``), используемый в командах, доступен во многих популярных оболочках, включая bash, zsh и Windows Powershell.

Очистка всех неиспользуемых или не связанных с контейнерами образов, контейнеров, томов и сетей

В Docker имеется команда, очищающая все не связанные с контейнерами ресурсы, в том числе образы, контейнеры, тома и сети:

docker system prune

Чтобы удалить все остановленные контейнеры и неиспользуемые образы (а не только образы, не связанные с контейнерами), добавьте в эту команду флаг -a:

docker system prune -a

Удаление образов Docker

Удаление одного или нескольких конкретных образов

Используйте команду docker images с флагом -a, чтобы найти идентификатор удаляемых образов. Эта команда покажет вам все образы, включая промежуточные слои образов. Когда вы определитесь с составом удаляемых образов, вы можете передать их идентификаторы или теги в docker rmi:

Список:

docker images -a

Удаление:

docker rmi Image Image

Удаление образов, не привязанных к контейнеру

Образы Docker состоят из нескольких слоев. Несвязанные образы — это слои, не имеющие связей с каким-либо образами с тегами. У них нет никакого назначения, и они просто занимают место на диске. Их можно найти, добавив флаг фильтра -f со значением dangling=true в команду docker images. Если вы уверены, что хотите удалить их, вы можете использовать команду docker images purge:

#drupal #docker #docker compose #docker images