当我尝试使用命令行docker build -t my-image-name .
构建以下Dockerfile时
FROM continuumio/miniconda3
EXPOSE 8880
# Set working directory
WORKDIR /my-workingdir
# Add scripts to docker workdir
ADD Dockerfile .
ADD environment.yml .
ADD all-my-python-files.py .
# Update & installation of linux packages
RUN apt-get update -y && \
apt-get install -y libgl1-mesa-glx apt-utils && \
apt-get install -y openssh-server && \
apt-get install -y net-tools
# Conda update and creation of environment
RUN conda update conda \
&& conda env create -f environment.yml \
# Activation of environment
&& echo "source activate environment" > ~/.bashrc
# Mount volumes
VOLUME /my-workingdir/Input
CMD ["python" , "execute_given_python_file.py"]
构建它时出现错误:
/bin/sh: 1: : not found
我正在macOS Hihg Sierra版本10.13.6中构建镜像,但是当我在Linux CentOS环境(在另一个Docker容器内部)中构建镜像时,Dockerfile可以完美运行。我在Mac上使用的Docker版本是我尝试了以下方法:
但是我仍然会出错。该如何解决?
更新:
在生成镜像期间,错误消息之前出现的最后几行是:
获取:6 http://security.debian.org/debian-security Stretch / updates / main amd64软件包[490 kB]
获取:7个http://deb.debian.org/debian Stretch-updates / main amd64软件包[5476 B]
获取:8 http://deb.debian.org/debian Stretch / main amd64软件包[9500 kB]
以2s(4564 kB / s)的速度获取10.3 MB
正在阅读包裹 list ...
/ bin / sh:1:找不到
Docker返回一个非零代码:127
为了复制错误,我提供了python脚本和yml环境。
错误期间测试了Python脚本all-my-python-files.py:
# Name of file: all-my-python-files.py
import openpyxl
import requests
import datetime as dt
import time
from pandas.io.json import json_normalize
import argparse
import os
import pandas as pd
print("At this point, libraries should be imported")
print("End of python script")
environment.yml文件为:
name: environment
channels:
- statiskit
- anaconda
- conda-forge
- defaults
dependencies:
- asn1crypto=0.24.0
# For space the following line are not separated into single lines:
-cffi = 1.11.5
-chardet = 3.0.4
-密码= 2.3.1
-et_xmlfile = 1.0.1
-idna = 2.7
-jdcal = 1.4
-openpyxl = 2.5.5
-pycparser = 2.18
-pyopenssl = 18.0.0
-pysocks = 1.6.8
-请求= 2.19.1
-urllib3 = 1.23
-ca-certificates = 2018.8.24
-openssl = 1.0.2p
-时间= 1.7
-blas = 1.0
-证书= 2018.8.24
-intel-openmp = 2018.0.3
-libedit = 3.1.20170329
-libffi = 3.2.1
#-libgfortran = 3.0.1#不在Linux中运行
-mkl = 2018.0.3
-mkl_fft = 1.0.4
-mkl_random = 1.0.1
-ncurses = 6.1
-numpy = 1.15.1
-numpy-base = 1.15.1
- Pandas = 0.23.4
-点= 10.0.1
-python = 3.7.0
-python-dateutil = 2.7.3
-pytz = 2018.5
-readline = 7.0
-setuptools = 40.2.0
-六个= 1.11.0
-sqlite = 3.24.0
-tk = 8.6.8
-车轮= 0.31.1
-xz = 5.2.4
-zlib = 1.2.11
#-libcxx = 4.0.1#不在Linux中运行
#-libcxxabi = 4.0.1#不在Linux中运行
-点:
-datetime == 4.2
-zope.interface == 4.5.0
前缀:/ Users / Elias / miniconda3 / envs / xlshp
最佳答案
正如@Charler Duffy提到的那样,问题与脚本中行的不可见结尾有关。以某种方式,通过以下方式编写代码解决了该问题:
RUN apt-get update
RUN apt-get install -y libgl1-mesa-glx apt-utils openssh-server net-tools
# Conda update and creation of environment
RUN conda update conda && \
conda env create -f environment.yml && \
# Activation of environment and correction of bash
echo "source activate xlshp_env" > ~/.bash
因此,当所有linux软件包都安装在同一行中时,Dockerfile可以构建镜像。