Docker containers are running but can't find them - docker

Yesterday I created 1 network and 3 containers for prestashop, phpmyadmin and mysql.
I saved them by running a docker save command and today when I came back my containers are still working on the specified ports however I can't see the containers by running docker ps -a. Also the prestashop folder is not writable anymore.
How can I see where my docker containers that are running ?
docker ps -a :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker network ls :
NETWORK ID NAME DRIVER SCOPE
e03870bf5fec bridge bridge local
63cfaacfbb2e chrono bridge local
c23a0b85edb9 host host local
1ae1b68b12c0 none null local
docker images :
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 5fab8d650e42 4 hours ago 657MB
prestadock_apache latest 740c640530f3 2 days ago 657MB
phpmyadmin latest f7fd780fedba 7 days ago 469MB
php 7.4-apache 899ab23566b7 7 days ago 414MB
mysql latest c8562eaf9d81 10 days ago 546MB
docker-compose.yml :
version: "3.8"
services:
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
container_name: chrono_db
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
networks:
- dev
phpmyadmin:
image: phpmyadmin:latest
container_name: chrono_phpmyadmin
restart: always
depends_on:
- db
ports:
- 8081:80
environment:
PMA_HOST: db
networks:
- dev
apache:
build: php
container_name: chrono_prestashop
ports:
- 8080:80
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- ./:/var/www/html
restart: always
networks:
- dev
networks:
dev:
volumes:
db-data:
Dockerfile :
FROM php:7.4-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN apt-get update \
&& apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev;
RUN echo "en_US.UTF8 UTF8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
mv composer.phar /usr/local/bin/composer
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
RUN a2enmod rewrite && service apache2 restart
RUN chown -R www-data:w
Here is the error after running docker-compose up -d :
ERROR: for chrono_prestashop Cannot start service apache: driver failed programming external connectivity on endpoint chronopiles_prestashop (11458be3c31e5f1107770b98ec5e56c645ac9e68b742fd4eb41ad965bd641e9c): Error starting userland proxy: listen tcp 0.0.0.0:8080: bind: address already in use

Related

Jenkins SSH remote hosts Can't connect to server

I can access to the target with ssh password and with the private key from Jenkins bash, I configured SSH sites on jenkins with the same host, User and private key I get the next error:
Docker logs:
2022-09-23 05:06:52.357+0000 [id=71] SEVERE o.j.h.p.SSHBuildWrapper$DescriptorImpl#doLoginCheck: Auth fail 2022-09-23 05:06:52.367+0000 [id=71] SEVERE o.j.h.p.SSHBuildWrapper$DescriptorImpl#doLoginCheck: Can't connect to server
Docker-compose:
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- $PWD/jenkins_home:/var/jenkins_home
networks:
- net
remote_host:
container_name: remote-host
image: remote-host
build:
context: fedora
dockerfile: Dockerfile
networks:
- net
db_host:
container_name: db
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=PASSWORD"
volumes:
- "$PWD/db:/var/lib/mysql"
networks:
- net
networks:
net:
DockerFile:
FROM fedora
RUN yum update -y
RUN yum -y install unzip
RUN yum -y install openssh-server
RUN useradd RemoteUser && \
echo "RemoteUser:Password"| chpasswd && \
mkdir /home/madchabelo/.ssh && \
chmod 700 /home/madchabelo/.ssh
COPY remote-ki.pub /home/madchabelo/.ssh/authorized_keys
RUN chown madchabelo:madchabelo -R /home/madchabelo/.ssh/ && \
chmod 600 /home/madchabelo/.ssh/authorized_keys
RUN ssh-keygen -A
RUN yum -y install mysql
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
sudo ./aws/install
RUN yum -y install vim
CMD /usr/sbin/sshd -D
I try with the IP and I get the same.
regards
When creating a private key, you should create a code with the following command after version ubuntu 20.04.
ssh-keygen -t ecdsa -m PEM -f remote-key
For a more detailed explanation, see the link below:
https://community.jenkins.io/t/ssh-connection-auth-fail/4121/7

Docker attach return no feedback

After starting my containers I try to attach it but I get no response; just blinking cursor
I do docker-compose up -d
[+] Running 2/2
⠿ Container mariadb Started 2.2s
⠿ Container backend Started
then docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85041e7609d4 backend "docker-php-entrypoi…" 10 seconds ago Up 7 seconds 0.0.0.0:8000->8000/tcp, 9000/tcp backend
412c03f5b410 mariadb "docker-entrypoint.s…" 11 seconds ago Up Less than a second 0.0.0.0:3306->3306/tcp mariadb
then docker attach 85041e7609d4
tried docker logs 85041e7609d4 but nothing there
if I docker run -ti --rm backend bash it works but this is not using the docker-compose
version: "3"
services:
backend:
container_name: backend
image: backend
restart: always
build: ./docker/backend/
ports:
- "8000:8000"
depends_on:
- mariadb
mariadb:
container_name: mariadb
restart: always
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: PASSWORD_ROOT
MYSQL_DATABASE: app
MYSQL_USER: USER
MYSQL_PASSWORD: PASSWORD
expose: ["3306"]
volumes:
- "db_data:/var/lib/mysql"
- "./database_dev.sql:/docker-entrypoint-initdb.d/database_dev.sql"
ports:
- "3306:3306"
volumes:
db_data:
backend image
FROM php:8.1.1-fpm
RUN apt-get clean && apt-get update \
&& apt-get install -y --no-install-recommends \
locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev unzip libpq-dev nodejs npm wget \
apt-transport-https lsb-release ca-certificates
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen
RUN curl -sS https://getcomposer.org/installer | php -- \
&& mv composer.phar /usr/local/bin/composer
RUN curl -sS https://get.symfony.com/cli/installer | bash \
&& mv /root/.symfony/bin/symfony /usr/local/bin
RUN docker-php-ext-configure \
intl \
&& docker-php-ext-install \
pdo pdo_mysql pdo_pgsql opcache intl zip calendar dom mbstring gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
RUN npm install --global yarn
CMD tail -f /dev/null
WORKDIR /var/www/app/
You've attached to a container running
tail -f /dev/null
This command has no output and accepts no input. Nothing will ever come out of /dev/null.
If you need a shell, you should exec that shell, e.g.
docker-compose exec backend bash
And if you want logs, the command you run should be your app, and your app should output logs.

Docker how to clear files on read only so I can change it directly from my computer and not container?

I created a docker-compose.yml file with the code below :
version: "3.8"
services:
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
container_name: docker_database
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
networks:
- dev
phpmyadmin:
image: phpmyadmin:latest
container_name: docker_phpmyadmin
restart: always
depends_on:
- db
ports:
- 8081:80
environment:
PMA_HOST: db
networks:
- dev
prestashop:
build: php
container_name: docker_prestashop
ports:
- 8080:80
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- ./:/var/www/html
restart: always
networks:
- dev
networks:
dev:
volumes:
db-data:
And also this Dockerfile :
FROM php:7.4-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN apt-get update \
&& apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev;
RUN echo "en_US.UTF8 UTF8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
mv composer.phar /usr/local/bin/composer
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
RUN a2enmod rewrite && service apache2 restart
The goal is to create a prestashop environnement however I'm struggling with a Error 500 when trying to install the prestashop. I've read that it has something to do with file permissions. Some of the folders are accessible but I don't know why some of them like the config folder is in read-only. I've created a volume that I share with container and host but I think I did something wrong on the configuration.
Even when I run a chmod 770 <some-file> I can access it but when I'm trying to change something in it I get this error :
Cannot save /home/benju/Bureau/docker/config/defines.inc.php.
Unable to create a backup file (defines.inc.php~).
The file left unchanged.
How could I access them with the same permission as the container on the host computer ?
You could use the use the same user and group with the docker run parameter, --user "$(id -u):$(id -g)"
with this the container can still give you an error, while bash on the container won't, but other applications can, because the user and group need to be created, so in the docker file,
ARG USER_ID
ARG GROUP_ID
RUN addgroup --gid $GROUP_ID user
RUN adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user
USER user
Then the file permissions which would be set by the container will on the volume will be the same as the host setting the file permissions.
More information on the following webpage,
https://vsupalov.com/docker-shared-permissions/
Here is what I've done and it worked (not sure if this is a good practice)
chown -R <hostuser>:<hostuser> <project root>

Docker Volume Persistence

I am trying to learn Docker. I have installed Docker Desktop on my Windows10 Pro computer.
I started with getting a PHP, MySQL website up and running using Docker.
My docker-compose.yml looks like
version: "3.8"
services:
www:
build: .
ports:
- "80:80"
volumes:
- ./www:/var/www/html
links:
- db
networks:
- default
db:
image: mysql:8.0
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_DATABASE: myDb
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- ./conf:/etc/mysql/conf.d
- persistent:/var/lib/mysql
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8000:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
and the DockerFile looks like
FROM php:7.3-apache
RUN docker-php-ext-install mysqli
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& apt-get install -y wget \
&& apt-get install -y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install zip
I have a www folder with an index.php.
When I run
docker-compose up -d
I have the PHP, mySQL site up and running correctly and I can access the index.php with expected results.
So far so good.
Now, I want to change the Dockerfile to setup a php forum website (phpbb) - so I have updated my Dockerfile as follows:
FROM php:7.3-apache
RUN docker-php-ext-install mysqli
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& apt-get install -y wget \
&& apt-get install -y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install zip
WORKDIR /var/www/html
RUN wget https://download.phpbb.com/pub/release/3.3/3.3.0/phpBB-3.3.0.tar.bz2 \
&& tar -xvjf phpBB-3.3.0.tar.bz2
&& ls -l
When I run
docker-compose build --no-cache
I can see the expected results - i.e, the "ls" command shows all the expected phpBB files in /var/www/html
However, when I run
docker-compose up -d
My container only has the index.php in the /var/www/html (the index.php from the www folder). None of the phpBB files are there.
What am I doing wrong?
The files are there but you are hiding them by your bind mount.
You are bind mounting ./www into the same directory (/var/www/html) which will hide its contents.
here:
www:
...
volumes:
- ./www:/var/www/html
When you are building the image, you correctly see the files but once you run docker-compose the bind mount is created and it hides those files.

How can I start Zookeper and Kafka both at the same time?

I wrote a python app that uses Kafka to share data between producer and consumer. I am going to dockerize it and so I wrote the dockerfile. The problem is in the final steps, when I run the Zookeeper server, it says binding to port .... and it never exits, so that it would be possible to run Kafka server also.
FROM ubuntu:18.04
ADD app.py /
RUN apt-get update -y && apt-get install -y apt-transport-https
RUN apt-get update \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get install gzip
RUN apt-get update \
&& apt-get install -y default-jdk \
&& rm -rf /var/lib/apt/lists/*
RUN wget http://mirrors.estointernet.in/apache/kafka/2.2.0/kafka_2.11-2.2.0.tgz
RUN tar -xvzf kafka_2.11-2.2.0.tgz
RUN cd kafka_2.11-2.2.0 \
&& ./bin/zookeeper-server-start.sh ./config/zookeeper.properties \
&& ./bin/kafka-server-start.sh ./config/server.properties
CMD [ “python”, “.app.py”]
Typically, you would only need to create a container for your own application. There are already numerous containers available for Kafka and Zookeeper.
A suggestion would be to run a simple Kafka stack using docker compose and then either start your application externally (for instance via command-line or IDE) or create a docker container and run it.
A simple Kafka stack with just Kafka and Zookeeper would require a simple docker-compose file with the following (of course you will need to have docker-compose installed on your system):
version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:4.0.0
restart: unless-stopped
ports:
- 2181:2181
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
kafka:
image: confluentinc/cp-kafka:4.0.0-2
depends_on:
- zookeeper
ports:
- 9092:9092
environment:
KAFKA_BROKER_ID: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
If you put the above in a file named simple-kafka-stack.yml, you can execute it by running the command:
docker-compose -f simple-kafka-stack.yml up

Resources