我对Docker中的某些行为感到困惑。 我在OSX主机上运行的最小Dockerfile:

FROM ubuntu:16.04

RUN apt-get update -y && \
  apt-get upgrade -y && \
  apt-get install -y gcc \
  build-essential \
  libmysqlclient-dev

RUN \
  echo mysql-server mysql-server/root_password password womp | debconf-set-selections && \
  echo mysql-server mysql-server/root_password_again password womp | debconf-set-selections && \
    apt-get -y install mysql-server

我用以下方法构建此图像:

docker build --tag wonk --file Dockerfile .

然后,我通过以下方式为此图像创建一个容器:

docker run -dit wonk

然后我找到了容器的ID:

docker ps -a

并使用它将外壳放入容器中:

docker exec -it {{ CONTAINER_ID }} /bin/bash

如果然后我尝试从客户端内部启动mysql服务器:

/etc/init.d/mysql start

但这失败了。

但是 ,如果我从docker文件中删除了整个第二条RUN命令,重复上述步骤,然后在容器内运行第二条RUN命令,则可以启动mysql。

有谁知道为什么会这样? 任何建议将非常有帮助!


编辑:实际上,虽然在上述两个容器中mysql的版本相同,但是在Dockerfile中安装mysql-server的版本以/var/lib/mysql/var/run/mysqld目录结尾,但是这些目录是在我从容器内部安装mysql-server的容器中不存在。 为什么会这样呢?


/var/log/mysql/error.log的内容

2019-09-18T23:39:50.957874Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2019-09-18T23:39:50.981668Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2019-09-18T23:39:51.162825Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-09-18T23:39:51.164124Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.27-0ubuntu0.16.04.1) starting as process 3456 ...
2019-09-18T23:39:51.168209Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-09-18T23:39:51.168258Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-09-18T23:39:51.168289Z 0 [Note] InnoDB: Uses event mutexes
2019-09-18T23:39:51.168319Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-09-18T23:39:51.168349Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2019-09-18T23:39:51.168378Z 0 [Note] InnoDB: Using Linux native AIO
2019-09-18T23:39:51.168600Z 0 [Note] InnoDB: Number of pools: 1
2019-09-18T23:39:51.168719Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-09-18T23:39:51.169949Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-09-18T23:39:51.178954Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-09-18T23:39:51.181161Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-09-18T23:39:51.194860Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-09-18T23:39:51.216975Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-09-18T23:39:51.217101Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-09-18T23:39:51.285152Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-09-18T23:39:51.287382Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-09-18T23:39:51.287434Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-09-18T23:39:51.288015Z 0 [Note] InnoDB: Waiting for purge to start
2019-09-18T23:39:51.339200Z 0 [Note] InnoDB: 5.7.27 started; log sequence number 2625955
2019-09-18T23:39:51.340684Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-09-18T23:39:51.340844Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-09-18T23:39:51.343146Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190918 23:39:51
2019-09-18T23:39:51.346475Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-09-18T23:39:51.346536Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2019-09-18T23:39:51.346580Z 0 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2019-09-18T23:39:51.346631Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2019-09-18T23:39:51.353776Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table storage engine for 'proxies_priv' doesn't have this option
2019-09-18T23:39:51.353845Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
2019-09-18T23:39:51.353946Z 0 [ERROR] Aborting

2019-09-18T23:39:51.354042Z 0 [Note] Binlog end
2019-09-18T23:39:51.354162Z 0 [Note] Shutting down plugin 'ngram'
2019-09-18T23:39:51.354209Z 0 [Note] Shutting down plugin 'partition'
2019-09-18T23:39:51.354246Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2019-09-18T23:39:51.354283Z 0 [Note] Shutting down plugin 'ARCHIVE'
2019-09-18T23:39:51.354318Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2019-09-18T23:39:51.354355Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2019-09-18T23:39:51.354390Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2019-09-18T23:39:51.354425Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2019-09-18T23:39:51.354461Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2019-09-18T23:39:51.354496Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2019-09-18T23:39:51.354531Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2019-09-18T23:39:51.354574Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2019-09-18T23:39:51.354612Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2019-09-18T23:39:51.354647Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2019-09-18T23:39:51.354683Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2019-09-18T23:39:51.354718Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2019-09-18T23:39:51.354753Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2019-09-18T23:39:51.354788Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2019-09-18T23:39:51.354823Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2019-09-18T23:39:51.354859Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2019-09-18T23:39:51.354897Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2019-09-18T23:39:51.354933Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2019-09-18T23:39:51.354968Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2019-09-18T23:39:51.355003Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2019-09-18T23:39:51.355039Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2019-09-18T23:39:51.355074Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2019-09-18T23:39:51.355109Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2019-09-18T23:39:51.355145Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2019-09-18T23:39:51.355180Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2019-09-18T23:39:51.355215Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2019-09-18T23:39:51.355251Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2019-09-18T23:39:51.355286Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2019-09-18T23:39:51.355321Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2019-09-18T23:39:51.355357Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2019-09-18T23:39:51.355392Z 0 [Note] Shutting down plugin 'InnoDB'
2019-09-18T23:39:51.355583Z 0 [Note] InnoDB: FTS optimize thread exiting.
2019-09-18T23:39:51.355914Z 0 [Note] InnoDB: Starting shutdown...
2019-09-18T23:39:51.462147Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2019-09-18T23:39:51.462633Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 190918 23:39:51
2019-09-18T23:39:52.922232Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2625974
2019-09-18T23:39:52.925597Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2019-09-18T23:39:52.925658Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2019-09-18T23:39:52.925694Z 0 [Note] Shutting down plugin 'MEMORY'
2019-09-18T23:39:52.925728Z 0 [Note] Shutting down plugin 'CSV'
2019-09-18T23:39:52.925763Z 0 [Note] Shutting down plugin 'MyISAM'
2019-09-18T23:39:52.925800Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2019-09-18T23:39:52.925902Z 0 [Note] Shutting down plugin 'sha256_password'
2019-09-18T23:39:52.925936Z 0 [Note] Shutting down plugin 'mysql_native_password'
2019-09-18T23:39:52.926081Z 0 [Note] Shutting down plugin 'binlog'
2019-09-18T23:39:52.926560Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

2019-09-18T23:39:53.037681Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

#1楼 票数:0

这似乎是一个特权问题。 您可以再次创建图像吗? 我已经对您的Dockerfile进行了一些优化:)

FROM ubuntu:16.04

RUN apt-get update -y && \
  apt-get upgrade -y && \
  apt-get install -y gcc \
  build-essential \
  libmysqlclient-dev && \
  echo mysql-server mysql-server/root_password password womp | debconf-set-selections && \
  echo mysql-server mysql-server/root_password_again password womp | debconf-set-selections && \
    apt-get -y install mysql-server

RUN chown -R mysql:mysql /var/lib/mysql /var/run/mysqld && \
    service mysql start

  ask by duhaime translate from so

未解决问题?本站智能推荐:

1回复

从dockerfile运行项目依赖项命令

我有一个laravel项目,要求: mysql数据库镜像 mongo数据库映像 依赖项:npm,作曲家,gulp,bower 所以我创建了一个包含3个服务docker-compose.yml : 好的,对于我的应用程序,我使用Dockerfile构建: 但是当然,某
1回复

dockerfile继承和RUN命令

我正在尝试创建一个 dockerfile 来构建一个 LAMP 服务器,以便使用alpine-lamp底座进行开发。 当我运行docker image build -t testing . 命令来构建我的图像我收到一个错误: 在“父”dockerfile 完成运行之前,我的 mysql 命令是否正在
1回复

dockerfile中的RUN命令产生的结果与在容器内手动运行相同命令的结果不同

我正在创建一个具有gcc 4.8.5的Ubuntu 12.04 docker镜像。 我正在获取gcc 4.8.5源代码并自己构建它。 该容器将在Ubuntu 18.04主机上运行。 引用底部的代码,如果我没有把它放在dockerfile中并在启动容器后运行相同的命令,那么构建工作正常,但
1回复

用于在docker容器中运行多个命令的bash命令

我正在尝试使用 docker 容器内的表来设置数据库。 为了正确运行 DB,我需要运行以下命令: --default-authentication-plugin=mysql_native_password ps:我不明白这个命令到底是干什么的,但它通过设置数据库来防止一些奇怪的日志。 对于设置,我
2回复

如何创建到dockerfile/mysql容器的ssh隧道

我正在寻找用于创建SSH隧道(在非标准端口上,例如3309)的正确语法,我可以在Mac OS X Yosemite终端上使用它,这将使我能够使用Sequel Pro连接到mysql容器在boot2docker中运行。 例如,我试过这个, 但它要求提供docker@192.168.59.1
1回复

服务mysql未运行Dockerfile

我有使用 Dockerfile 运行 mysql 的问题 构建图像适用于此代码,但当我尝试运行 service mysql start 时,在容器中找不到 mysql 服务。 由于某些根安全问题,mysqld 命令不会运行。 有人可以帮忙吗? 谢谢你。
8回复

如何从主机到运行MySQL服务器的容器执行MySQL命令?

我已按照https://registry.hub.docker.com/_/mysql/ 中的说明提取映像并运行容器,其中运行 MySQL 服务器。 容器在后台运行,我想运行一些命令。 哪个是连接到容器并从命令行执行此命令的最佳方式? 谢谢。
1回复

容器未使用提及的dockerfile构建-多个容器

我正在使用一个主内核应用程序,该应用程序使用mysql和influxdb作为数据库和grafana以图形方式显示数据的情况。 我正在使用Dockerfile docker-compose和单独的Dockerfile为每个容器创建单独的容器。 文件夹结构如下: dockercompose