繁体   English   中英

Dockerfile的输出不等于容器内运行的相同命令的输出

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

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

我对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 个回复

这似乎是一个特权问题。 您可以再次创建图像吗? 我已经对您的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
1 即使输出相同,为什么s1不等于s3?

谁能告诉我为什么行“ System.out.println(s1.equals(s3));” 返回输出“假”,即使输出相同? 我已经尝试了10个小时,似乎无法弄清原因。 ...

2015-10-21 13:02:25 3 76   java
2 相同命令给出不同的输出

我正在尝试执行命令: 它为我提供了进程名称为“ some-process-name”的进程的pid。 但是,当我在Shell脚本中使用相同的long命令时,进程名称作为命令行参数传递并通过“ $ 1”使用,则在输出中得到两个pid。 这可能是什么原因? 有什么建议么? ...

2012-07-07 15:42:58 1 73   shell
3 如何输出不等于3的所有电平?

我想显示所有级别,该长度(如character )不等于3个符号。 以下代码为每一行返回dt$col长度: 但是,如果我将levels(dt$col)作为第一个参数传递,它将失败并显示以下错误: eval(替代(expr),数据,enclos = parent.frame ...

6 uTensor模型输出不等于预期输出

我目前正在研究需要uTensor的项目。 uTensor似乎正常工作,但是我遇到了一个(显然)无法修复自己的问题。 问题定义 我创建了一个简单的python脚本,该脚本生成模型并将其保存到文件中。 稍后可以使用uTensor-cli将保存的模型转换为C ++代码。 生成的C + ...

7 RMAN备份-使用相同命令的不同输出

当我将语法的一部分保留在中间,而将语法的另一部分保留在最后时,它将备份存储在不同的位置,我看到使用“格式关键字”的RMAN'备份数据库'命令的不同输出或行为,如以下情况所述 在以下情况1中-我在中间使用了format关键字,并将备份集保存在定义的位置,但是,如果最后使用与format关键字 ...

8 使用exec的相同命令给出不同的输出

我正在从一台服务器迁移到另一台服务器,并看到相同的exec命令给出了不同的输出。 我不确定我需要检查并确保我看到一致的输出 1)服务器1(这是我想要的) 服务器2(这是我在新服务器中得到的): 两台服务器上的Java版本相同,如下所示 另外,该命令不会在新服务器 ...

9 从sql脚本输出中提取不等于零的值

我基本上是在2个不同的数据库之间对具有相同名称的表进行行计数。 我们的sql脚本是这样的: 我们有将近2000个与上述相似的脚本。 输出如下: 现在使用bash / shell脚本,我想将输出仅打印到数值不等于0的那三行的单独文件中。 例: ...

暂无
暂无

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

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