如何将值传递给docker文件

时间:2018-03-09 10:58:11

标签: docker dockerfile docker-container

这是我的泊坞文件

FROM ubuntu:16.04
   
   RUN apt-get update && apt-get install -y wget && \
       wget https://dev.mysql.com/get/Downloads/MySQL-Router/mysql-router_2.1.6-1ubuntu16.04_amd64.deb && \
       apt-get install -y ./mysql-router_2.1.6-1ubuntu16.04_amd64.deb && \
       apt-get update && \
       apt-get install mysql-router && \
       useradd -ms /bin/bash router
   USER router
   WORKDIR /home/router
   RUN mysqlrouter --bootstrap ic@192.168.1.136:3306 -d myrouter
   
   CMD ["myrouter/start.sh"]

这是Docker交互式输出:

Sending build context to Docker daemon  2.048kB
       Step 1/6 : FROM ubuntu:16.04
        ---> f975c5035748
       Step 2/6 : RUN apt-get update && apt-get install -y wget &&     wget https://dev.mysql.com/get/Downloads/MySQL-Router/mysql-router_2.1.6-1ubuntu16.04_amd64.deb &&     apt-get install -y ./mysql-router_2.1.6-1ubuntu16.04_amd64.deb &&     apt-get update &&     apt-get install mysql-router &&     useradd -ms /bin/bash router
        ---> Using cache
        ---> 1bf5a87eb556
       Step 3/6 : USER router
        ---> Using cache
        ---> ccedbc3db924
       Step 4/6 : WORKDIR /home/router
        ---> Using cache
        ---> ab67e9623a09
       Step 5/6 : RUN mysqlrouter --bootstrap ic@192.168.1.136:3306 -d myrouter
        ---> Running in 9494d8083fd0
       Please enter MySQL password for ic: 
   Error: Unable to connect to the metadata server: Error connecting to MySQL server at 192.168.1.136:3306: Access denied for user 'ic'@'192.168.1.164' (using password: NO) (1045)
   The command '/bin/sh -c mysqlrouter --bootstrap ic@192.168.1.136:3306 -d myrouter' returned a non-zero code: 1

步骤5/6 中,我需要输入密码,但我不知道如何在docker文件中传递密码。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

最后,我得到了解决方案。这里我使用shell脚本文件来传递密码

这是我的泊坞文件

FROM ubuntu:16.04
    RUN apt-get update && apt-get install -y wget && \
        wget https://dev.mysql.com/get/Downloads/MySQL-Router/mysql-router_2.1.6-1ubuntu16.04_amd64.deb && \
        apt-get install -y ./mysql-router_2.1.6-1ubuntu16.04_amd64.deb && \
        apt-get update && \
        apt-get install mysql-router && \
        useradd -ms /bin/bash router
    USER router
    WORKDIR /home/router
    COPY script.sh /script.sh
    RUN /script.sh
    CMD ["myrouter/start.sh"]

这是我的script.sh文件

#!/bin/bash
mysqlrouter --bootstrap ic@192.168.1.136:3306 -d myrouter <<< "password"