繁体   English   中英

Output 的 Dockerfile 不等于 output 的相同命令在容器内运行

[英]Output of Dockerfile not equal to output of same commands run inside container

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

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

并使用它在容器内放置 shell :

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

这似乎是一个特权问题。 你能再创建一个图像吗? 我已经优化了你 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM