0

I am trying to set up a Dockerfile with an ubuntu image that runs a mysql server (I know I should use the mysql image instead, but I need to do it this way for an assignment). I am having a lot of trouble designing the Dockerfile. My Dockerfile looks like this right now:

FROM ubuntu:latest

EXPOSE 3306

VOLUME [ "/var/lib/mysql" ]

RUN apt update && \
    apt install -y mysql-server && \
    apt-get install -y gosu

ENV MYSQL_ROOT_PASSWORD=secret

COPY ./wordpress.sql /docker-entrypoint-initdb.d/

COPY ./docker-entrypoint.sh /usr/local/bin/

COPY ./entrypoint.sh /

RUN chmod +x entrypoint.sh && \
    chmod +x /docker-entrypoint-initdb.d/wordpress.sql && \
    chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]

CMD [ "mysqld" ]

(I am running docker build -t sql . to build the image, and docker run --name sql_cont -v sql_vol:/var/lib/mysql sql_img to run the container)

I have a folder where I have the docker-entrypoint.sh file and the entrypoint.sh file, because when I install mysql-server, these files are not created by default as If I was just using the mysql docker image.

I just need a Dockerfile from an ubuntu image that runs mysql and just stays waiting ready for connections, so, If anybody know how to refactor this Dockerfile or just give me the answer I'd much appreciate it.

lazlomeli
  • 61
  • 7
  • You have two entrypoint scripts; what's the difference, and what are they intended to do? What happens when you run the container, and what goes wrong? What's actually in the `docker-entrypoint.sh` script (the one that winds up in `/usr/local/bin`)? – David Maze Nov 06 '22 at 17:38
  • Both entrypoint.sh and docker-entrypoint.sh have the same code (the default entrypoint.sh mysql file code) and when I run the container it looks like it works but it stays at [Entrypoint] MySQL Server has started or something like that (instead it should actually initialize the database and be ready for connections) – lazlomeli Nov 06 '22 at 18:11

1 Answers1

0

If I got What is the difference between CMD and ENTRYPOINT in a Dockerfile? right, the argument in CMD will be passed to the ENTRYPOINT. Don’t know about your ENTRYPOINT script, but I expect it to just ignore parameters.

I would suggest to:

  • not replace the default ENTRYPOINT (defaults to /bin/sh -c)
  • start the docker-entrypoint.sh from CMD
  • Append mysqld to docker-ENTRYPOINT.sh
PHagemann
  • 71
  • 5
  • 1
    A well-written entrypoint wrapper script will end with `exec "$@"`, which will run the command passed to it as arguments. – David Maze Nov 06 '22 at 17:36
  • I removed the entrypoint and did this to CMD: `CMD ["docker-entrypoint.sh", "mysqld"],` the output is the same, the container runs and just gets stuck at `[Entrypoint]: Entrypoint script for MySQL Server started.` (it should instead initialize the db and get ready for connections) – lazlomeli Nov 06 '22 at 18:16
  • Thanks to @DavidMaze. Didn’t know about that. Could you provide more details about your ENTRYPOINT script? – PHagemann Nov 07 '22 at 14:52
  • [This answer](https://stackoverflow.com/questions/63198731/how-to-use-wait-for-it-in-docker-compose-file/63200666#63200666) has a fairly typical example, waiting for an external database to be available and then running the `CMD`. – David Maze Nov 07 '22 at 15:54