我不确定如何命名Dockerfiles.很多GitHub在Dockerfile没有文件扩展名的情况下使用.我给他们一个名字和名字吗?如果是这样的话?或者我只是打电话给他们Dockerfile?
我通过运行以下命令在centos 7上安装了docker.
curl -sSL https://get.docker.com/ | sh
systemctl enable docker && systemctl start docker
docker run hello-world
Run Code Online (Sandbox Code Playgroud)
注意:helloworld运行正常,没有问题.
但是,当我试图运行docker-compose(docker-compose.yml存在且有效)时,它只给我Centos上的错误(Windows版本适用于docker-compose文件)
/usr/local/bin/docker-compose: line 1: {error:Not Found}: command not found
Run Code Online (Sandbox Code Playgroud) Dockerfile.1执行多个RUN:
FROM busybox
RUN echo This is the A > a
RUN echo This is the B > b
RUN echo This is the C > c
Run Code Online (Sandbox Code Playgroud)
Dockerfile.2 加入他们:
FROM busybox
RUN echo This is the A > a &&\
echo This is the B > b &&\
echo This is the C > c
Run Code Online (Sandbox Code Playgroud)
每个都RUN创建一个图层,所以我总是认为更少的图层更好,因此Dockerfile.2更好.
当RUN删除由前一个RUN(即yum install nano && yum clean all)添加的内容时,这显然是正确的,但是在每个RUN添加内容的情况下,我们需要考虑以下几点:
图层都应该只是添加高于前一个差异,所以如果以后层不会删除的东西在前面的一个补充,不存在应节省多少磁盘空间这两种方法之间的优势...
从Docker …
什么是.build-deps在下面的命令?我无法在Alpine文档中找到解释.这是一个预定义的文件吗?在许多Dockerfiles中都会看到这个引用.
RUN apk add --no-cache --virtual .build-deps \
gcc \
freetype-dev \
musl-dev
RUN pip install --no-cache-dir <packages_that_require_gcc...> \
RUN apk del .build-deps
Run Code Online (Sandbox Code Playgroud) 这可能是一个微不足道的问题,但阅读ARG和ENV的文档并不能让我明白.
我正在构建一个PHP-FPM容器,我希望能够启用/禁用一些用户需求扩展.
如果可以在Dockerfile中通过添加条件并在构建命令上传递标志来完成,那将是很好的,但是不支持AFAIK.
在我的情况下,我个人的方法是在容器启动时运行一个小脚本,如下所示:
#!/bin/sh
set -e
RESTART="false"
# This script will be placed in /config/init/ and run when container starts.
if [ "$INSTALL_XDEBUG" == "true" ]; then
printf "\nInstalling Xdebug ...\n"
yum install -y php71-php-pecl-xdebug
RESTART="true"
fi
...
if [ "$RESTART" == "true" ]; then
printf "\nRestarting php-fpm ...\n"
supervisorctl restart php-fpm
fi
exec "$@"
Run Code Online (Sandbox Code Playgroud)
这是我的Dockerfile样子:
FROM reynierpm/centos7-supervisor
ENV TERM=xterm \
PATH="/root/.composer/vendor/bin:${PATH}" \
INSTALL_COMPOSER="false" \
COMPOSER_ALLOW_SUPERUSER=1 \
COMPOSER_ALLOW_XDEBUG=1 \
COMPOSER_DISABLE_XDEBUG_WARN=1 \
COMPOSER_HOME="/root/.composer" \ …Run Code Online (Sandbox Code Playgroud) 以下是我的"Dockerfile"的内容
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
# change working dir to /usr/src/app
WORKDIR /usr/src/app
VOLUME . /usr/src/app
RUN npm install
EXPOSE 8080
CMD ["node" , "server" ]
Run Code Online (Sandbox Code Playgroud)
在这个文件中,我期待"VOLUME./ usr/src/app"指令将主机中当前工作目录的内容挂载到容器的/ usr/src/app文件夹中.
如果这是正确的方法,请告诉我?
是否可以在一个命令的帮助下构建和运行Dockerfile,因为有一个命令docker build可以构建Dockerfile并docker run -it运行命令.
是否有这两个命令的任意组合,只需一个命令就可以更容易地构建和运行?
我有一个Dockerfile.构建映像时,构建会因此错误而失败:
automake: error: no 'Makefile.am' found for any configure output
Error build: The command [/bin/sh -c aclocal && autoconf && automake -a] returned a non-zero code: 1
Run Code Online (Sandbox Code Playgroud)
实际上是无害的.该库构建正常,但Docker一旦收到此错误就停止构建.有什么方法可以指示Docker忽略它吗?
我想链接2个单独的容器:
问题是PHP脚本不起作用.也许php-fpm配置不正确.这是源代码,位于我的存储库中.这是文件docker-compose.yml:
nginx:
build: .
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www/test/
links:
- fpm
fpm:
image: php:fpm
ports:
- "9000:9000"
Run Code Online (Sandbox Code Playgroud)
和Dockerfile我使用了基于nginx的一个建立一个自定义图像:
FROM nginx
# Change Nginx config here...
RUN rm /etc/nginx/conf.d/default.conf
ADD ./default.conf /etc/nginx/conf.d/
Run Code Online (Sandbox Code Playgroud)
最后,这是我的自定义Nginx虚拟主机配置:
server {
listen 80;
server_name localhost;
root /var/www/test;
error_log /var/log/nginx/localhost.error.log;
access_log /var/log/nginx/localhost.access.log;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass 192.168.59.103:9000;
fastcgi_split_path_info …Run Code Online (Sandbox Code Playgroud) 我想/etc/hosts在"docker build"期间更新我的文件.
我在Dockerfile中添加了以下行,但它既没有更新/etc/hosts文件也没有给出任何错误.
RUN echo "192.168.33.11 mynginx" >> /etc/hosts
Run Code Online (Sandbox Code Playgroud)
我需要更新/etc/hosts.任何人都可以建议吗?