never set the container up as 'up' [docker] - mysql

I made a Dockerfile and a docker-compose.yml myself and attempted to make containers from the docker-compose.yml.
The apache container works properly: stable but the db container doesn't.
It never becomes the status up.
/work_space
|-eccube #docker-compose.yml
| #Dockerfile
|
|-eccube-data #db
#data
#ececcube-2.4.1
#html
Used docker logs <db container ID> to see what happened ↓
Initializing database
2019-05-22T07:59:02.264102Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-22T07:59:02.266227Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-05-22T07:59:02.267061Z 0 [ERROR] Aborting
Dockerfile
FROM centos:7
RUN yum update -y
RUN yum install -y sudo
RUN yum install -y epel-release
RUN yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
RUN yum clean all
RUN yum -y install wget
RUN yum -y install httpd
RUN yum -y install --enablerepo=remi,remi-php52 php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt php-pgsql
RUN wget http://downloads.ec-cube.net/src/eccube-2.4.1.tar.gz
RUN tar zxvf eccube-2.4.1.tar.gz
RUN mv -f /eccube-2.4.1/data/ /var/www/data
RUN mv -f /eccube-2.4.1/html/ /var/www/html
RUN rm -rf eccube-2.4.1
RUN rm -rf eccube-2.4.1.tar.gz
CMD ["/usr/sbin/httpd", "-DFOREGROUND"]
EXPOSE 80
docker-compose.yml
version: '3'
services:
apache:
build: .
privileged: true
tty: true
ports:
- 80:80
volumes:
- /work_space/eccube-data/html:/var/www/html
- /work_space/eccube-data/data:/var/www/data
db:
image: mysql:5.7
privileged: true
tty: true
ports:
- 6666:3306
volumes:
- /work_space/eccube-data/db:/var/lib/mysql
environment:
- MYSQL_DATABASE:'cube2_dev'
- LANG=C.UTF-8
- MYSQL_ROOT_PASSWORD=root
I'll show you code/file you need to figure this out.
/w/eccube ❯❯❯ docker ps ✘ 1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
251df77751fe eccube_apache "/usr/sbin/httpd -DF…" About an hour ago Up About an hour 0.0.0.0:80->80/tcp eccube_apache_1
/w/eccube ❯❯❯ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b857c8b211ca mysql:5.6 "docker-entrypoint.s…" About an hour ago Exited (1) About an hour ago eccube_db_1
251df77751fe eccube_apache "/usr/sbin/httpd -DF…" About an hour ago Up About an hour 0.0.0.0:80->80/tcp eccube_apache_1
In var/lib/mysql, these files & dirs exist.
root#f4680fa4d3f4:/var/lib/mysql# ls
auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql private_key.pem server-cert.pem sys
ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 performance_schema public_key.pem server-key.pem
And then, In /work_space/eccube_data/db, indeed, those wewe kind of Synchronized!!!
/w/e/db ❯❯❯ ls
auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql private_key.pem server-cert.pem sys
ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 performance_schema public_key.pem server-key.pem

With Docker for Mac, the following stores data inside the embedded VM since there is no mapping for this directory to your Mac environment:
- /work_space/eccube-data/html:/var/www/html
- /work_space/eccube-data/data:/var/www/data
and
- /work_space/eccube-data/db:/var/lib/mysql
Instead, you want to use relative paths:
- ../eccube-data/html:/var/www/html
- ../eccube-data/data:/var/www/data
and
- ../eccube-data/db:/var/lib/mysql
This assumes you run your docker-compose commands from inside the eccube directory, and that your project is inside the /Users directory, which is case sensitive (see more about using other directories in the Docker for Mac getting started guide).

I deleted container, image and volume, and then executed docker-compose up -d.
It worked.
Now I have the containers properly.
Thank you so much!

Related

docker: run mysql container with specific uid:gid

i am building an app stack where mysql is one of the services. I want all services to run as uid 1000:1000, so i dont have any trouble with permissions on the host system.
Now i have problems doing this with the official mysql docker image.
Here is what i do:
FROM mysql:5.7
RUN addgroup --gid 1000 app \
&& adduser --gecos "" --home /home/app --shell /bin/bash --disabled-password --uid 1000 --gid 1000 app \
&& adduser app mysql \
&& adduser mysql app
RUN chown -R app:app /var/lib/mysql && chmod -R g+wrx /var/lib/mysql
COPY mysql.cnf /etc/mysql/conf.d/99-docker.cnf
COPY .my.cnf /home/app/.my.cnf
COPY .root.cnf /root/.my.cnf
RUN chmod 0664 /etc/mysql/conf.d/99-docker.cnf
USER app
EXPOSE 3306
And the service in my compose file:
version: "3"
services:
mysql:
build:
context: ./docker/mysql
dockerfile: Dockerfile
env_file:
- .env
volumes:
- ./var/mysql:/var/lib/mysql
user: 1000:1000
ports:
- 3307:3306
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
The env file contains some vars for mysql:
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=app
MYSQL_USER=app
MYSQL_PASSWORD=app
the .my.cnf files contain credentials
the mysql config contains some cache settings, sql-mode and:
[mysqld]
user=app
when starting the service with: docker-compose up --build mysql i get the following error:
mysql_1 | Initializing database
mysql_1 | mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)
mysql_1 | 2020-04-09T11:11:25.664285Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1 | 2020-04-09T11:11:25.664345Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
mysql_1 | 2020-04-09T11:11:25.666725Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
mysql_1 | 2020-04-09T11:11:25.666744Z 0 [ERROR] Aborting
mysql_1 |
pixel3_mysql_1 exited with code 1
When running docker-compose run mysql bash and inspecting the files i see, that the /var/lib/mysql directory is root-owned.
In the documentation (https://hub.docker.com/_/mysql) it says i can run the image with another user but to me it seems this is not possible.
Do i have to override the entrypoint to chown the directories over and over again or what is my mistake?

How to install mysql-server in a Dockerfile?

I have a complex Dockerfile which install much more than just mysql-server so I cannot start from an existing mysql container.
When removing all the extra-stuff I get this Dockerfile
FROM ubuntu:latest
ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_ROOT_USER=root
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y mysql-server
RUN usermod -d /var/lib/mysql/ mysql
RUN service mysql start
Unfortunately, mysql does not want to start:
---> 57a66bd64c2c
Step 8/9 : RUN usermod -d /var/lib/mysql/ mysql
---> Running in 596df248c2e4
---> ee78442bcc56
Step 9/9 : RUN service mysql start
---> Running in 0d9e5803cf33
* Starting MySQL database server mysqld
...fail!
The command '/bin/sh -c service mysql start' returned a non-zero code: 1
What is my mistake?
Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.
FROM oraclelinux:7-slim
ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm
# Install server
RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql \
&& yum install -y $PACKAGE_URL \
&& yum install -y libpwquality \
&& rm -rf /var/cache/yum/*
RUN mkdir /docker-entrypoint-initdb.d
VOLUME /var/lib/mysql
COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 3306 33060
CMD ["mysqld"]
You need to include a proper source with correct version to pull the image from.
and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.

Bootstraping Percona Xtradb Cluster in Docker gives the error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

My goal is to get a Percona XtraDB Installation running in a Docker Container.
For this i wrote up the following configuration.
Dockerfile:
FROM ubuntu:wily
ENV DEBIAN_FRONTEND noninteractive
#
# ENVIRONMENT INSTALL
#
RUN apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get install -y wget curl netcat python-dev python-setuptools python-software-properties vim
RUN easy_install j2cli
COPY my.cnf.j2 /templates/
COPY docker-entrypoint.sh /
RUN chmod +x docker-entrypoint.sh /
#
# PERCONA XTRADB CLUSTER INSTALL
#
RUN echo "deb http://repo.percona.com/apt wily main" >> /etc/apt/sources.list.d/percona.list
RUN echo "deb-src http://repo.percona.com/apt wily main" >> /etc/apt/sources.list.d/percona.list
RUN apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
RUN apt-get update && apt-get install -y percona-xtradb-cluster-56
ENTRYPOINT ["/docker-entrypoint.sh"]
docker-entrypoint.sh
#!/bin/bash -e
j2 /templates/my.cnf.j2 > /etc/mysql/my.cnf
exec bash
my.cnf.j2
[mysqld]
user=mysql
default_storage_engine=InnoDB
basedir=/usr
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
innodb_autoinc_lock_mode=2
log_queries_not_using_indexes=1
max_allowed_packet=128M
binlog_format=ROW
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_node_address={{node_ip}}
wsrep_cluster_name="mycluster"
wsrep_cluster_address=gcomm://
wsrep_node_name={{node_name}}
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="test:test"
!includedir /etc/mysql/conf.d/
wsrep_cluster_address=gcomm:// normally holds a list of 3 node WAN-IPs, i removed them due to privacy.
Building the image works perfectly fine with:
docker build --rm -t test .
Starting works also fine with:
docker run --name Test1 -e "node_ip=127.0.0.1" -e "node_name=Test1" -p 3306:3306 -p 4567:4567 -p 4444:4444 -p 4568:4568 -i -t test
The variable node_ip points at the WAN-IP of my server, i set it to 127.0.0.1 just for privacy reasons.
But when i try to bootstrap mysql in the container with:
/etc/init.d/mysql bootstrap-pxc
I get this error:
2016-03-28 09:24:09 354 [Note] Server hostname (bind-address): '*'; port: 3306
2016-03-28 09:24:09 354 [Note] IPv6 is available.
2016-03-28 09:24:09 354 [Note] - '::' resolves to '::';
2016-03-28 09:24:09 354 [Note] Server socket created on IP: '::'.
2016-03-28 09:24:09 354 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
160328 09:24:09 mysqld_safe mysqld from pid file /var/lib/mysql/8605688929d8.pid ended
How can i solve this to get the XtraDB running in my Container?
mysql_install_db
chown mysql.mysql -R /var/lib/mysql
service mysql start
The above appears to work without issue, please test it out.
It could be a permissions problem. Try adding the following after your FROM statment:
RUN useradd mysql \
&& mkdir /var/lib/mysql \
&& chown -R mysql:mysql /var/lib/mysql

Docker - can not start mysql permission error

I have problem with docker and mysql. I have build an image based on phusion/baseimage. I want to create image where /var/lib/mysql directory is shared with my host (OS X), because I dont want to store my data on container.
Everything works fine when directory /var/lib/mysql is not shared. When I share this directory, mysql service can not start. In logs are informations about problems with permissions while starting.
Result of ls -la from /var/lib is:
[...]
drwxr-xr-x 1 lc staff 170 Jan 3 16:55 mysql
[...]
The mysql user should be an owner. I tried to do:
sudo chown -R mysql:mysql mysql/
But this command didn't return any error and didn't change owner.
I have also tried to add my user (from container) to mysql group:
lc#cbe25ac0681e:~$ groups lc
lc : lc sudo mysql
But It also didn't work. Have anybody any idea how to solve this issue?
My docker-compose.yml file:
server:
image: lukasz619/light-core_server
ports:
- "40080:80"
- "40022:22"
- "40443:443"
- "43306:3306"
volumes:
- /Users/lukasz/Workspace/database/mysql:/var/lib/mysql
This is my Dockerfile:
FROM phusion/baseimage
RUN apt-get update
RUN apt-get install -y apache2
# Enable SSH
RUN rm -f /etc/service/sshd/down
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh
# public key for root
ADD public_key.pub /tmp/public_key.pub
RUN cat /tmp/public_key.pub >> /root/.ssh/authorized_keys && rm -f /tmp/public_key.pub
EXPOSE 80
CMD ["/sbin/my_init"]
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
When we say that users are shared between the container and the host, it's not quite true; it's the UIDs that are actually shared. What this means is that the user named mysql in the container most likely has a different UID to the user mysql on the host.
We can try to fix this by using the image to set the permissions:
docker run --user root lukasz619/light-core_server chown -R mysql:mysql /var/lib/mysql
This may work, depending on how you've set up the image. There is also a further complication from the VM running in-between.
The problem is OS X.. I ran this docker-composer.yml
server:
image: lukasz619/light-core_server
ports:
- "40080:80"
- "40022:22"
- "40443:443"
- "43306:3306"
volumes:
- /var/mysql:/var/lib/mysql
Its possible to share directories (and do chown) ONLY between boot2docker and container, but do not work properly shareing between Os X and container.

how can i create a database on mysql docker service

I'm trying to run moodle phpunit on my gitlab ci server. Using gitlab-ci.yml file i'm creating a container with php 5.6 and mysql service.
# Services
services:
- mysql:latest
before_script:
- mysql -e 'CREATE DATABASE gitlab_ci_test DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;' ;
I'm getting ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) and not sure how to proceed.
Tomasz this is my gitlab-ci.yml file you will need something like this:
# Select image from https://hub.docker.com/r/_/php/
image: php:7.0.0
services:
- mysql:5.7
variables:
# Configure mysql environment variables (https://hub.docker.com/r/_/mysql/)
MYSQL_DATABASE: symfony
MYSQL_ROOT_PASSWORD: qwerty
# Composer stores all downloaded packages in the vendor/ directory.
# Do not use the following if the vendor/ directory is commited to
# your git repository.
cache:
paths:
- vendor/
before_script:
# Install dependencies
- bash ci/docker_install.sh > /dev/null
- cp ci/parameters.yml app/config/parameters.yml
- composer install
test:app:
script:
- phpunit
And this is my docker_install.sh inside ci folder
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && [[ ! -e /.dockerinit ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
apt-get install wget -yqq
apt-get install zip unzip -yqq
# Install composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Install phpunit, the tool that we will use for testing
curl -o /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
chmod +x /usr/local/bin/phpunit
# Install mysql driver
# Here you can install any other extension that you need
docker-php-ext-install pdo pdo_mysql mbstring