0

I am creating a development/testing container that contains a number of elements including a mysql server that must run internally for code to access. To demonstrate the issue, I run the following Dockerfile with docker run -i -t demo_mysql_server:

FROM amazonlinux:2018.03

RUN yum -y update && yum -y install shadow-utils mysql-server

Unfortunately, after building the docker container I receive a common connection error (see 1, 2)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

which can be fixed by logging in as admin with docker run -i -u 0 -t demo_mysql_server and executing:

echo "NETWORKING=yes" >/etc/sysconfig/network
service network restart
/etc/init.d/mysqld start
chkconfig mysqld on

which seems to turn everything on. However, incorporating these into RUN commands doesn't seem to keep the service on and logging in as admin requires restarting the service as above and adding a user and working as a non-admin and trying to start the service results in errors of the flavor:

bash: /etc/sysconfig/network: Permission denied
[testUser@544a938c44c1 /]$ service network restart
[testUser@544a938c44c1 /]$ /etc/init.d/mysqld start
/etc/init.d/mysqld: line 16: /etc/sysconfig/network: No such file or directory
[testUser@544a938c44c1 /]$ chkconfig mysqld on
You do not have enough privileges to perform this operation.

I this a normal error to see and how do I get the MySQL server instance to stay running?

Steve
  • 3,957
  • 2
  • 26
  • 50
  • Usually you’d just `docker run mysql` to run the database in a separate container. As a broad rule commands like `service` and `chkconfig` don’t really work in Docker: a container should usually run one process as a foreground job, and that’s usually not something that knows about init scripts. – David Maze Sep 23 '19 at 20:51
  • @DavidMaze That's a helpful observation. Unfortunately, the server the container is setup required to replicate has a webserver, python, and internal mysql server running on localhost so I need it. – Steve Sep 24 '19 at 13:27
  • You’re probably looking for a full virtual machine setup, if your goal is “replicate a server”. You can probably even use the same deployment tools you’re using now (like Chef or Ansible) to set up the VM, instead of going into the dedicated Docker tooling. – David Maze Sep 24 '19 at 14:58

0 Answers0