繁体   English   中英

我已经制作了一个dockerfile,我打算在AWS ECS上运行它,但是我不能按要求-t

[英]I have made a dockerfile and I was going to run it on AWS ECS but I cant as it requires -t

这是我的docker run,并且docker文件是为什么它需要-t并且在ECS上不工作的原因,感谢您的帮助。 我不明白-t会做什么,如果有人也可以提供帮助的话。

这只是一个连接到我的rds并使用wordpress的基本docker。 我没有任何插件,因此,这正是我使用的主题。

command docker run -t --name wordpress -d -p 80:80 dockcore/wordpress 



FROM ubuntu

#pt-get clean all
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install unzip wget mysql-client mysql-server apache2 libapache2-mod-php7.0 pwgen python-setuptools vim-tiny php7.0-mysql  php7.0-lda
RUN rm -fr /var/cashe/*files neeeded
ADD wordpress.conf /etc/apache2/sites-enabled/000-default.conf

# Wordpress install
RUN wget -P /var/www/html/ https://wordpress.org/latest.zip
RUN unzip /var/www/html/latest.zip -d /var/www/html/
RUN rm -fr /var/www/html/latest.zip

# Copy he wp config file
RUN cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

# Expose web port
EXPOSE 80

# wp config for database
RUN sed -ie 's/database_name_here/wordpress/g' /var/www/html/wordpress/wp-config.php
RUN sed -ie 's/username_here/root/g' /var/www/html/wordpress/wp-config.php
RUN sed -ie 's/password_here/password/g' /var/www/html/wordpress/wp-config.php
RUN sed -ie 's/localhost/wordpressrds.xxxxxxxxxxxxxx.ap-southeast-2.rds.amazonaws.com:3306/g' /var/www/html/wordpress/wp-config.php
RUN rm -fr /var/www/html/wordpress/wp-content/themes/*
RUN rm -fr /var/www/html/wordpress/wp-content/plugins/*
ADD /shapely /var/www/html/wordpress/wp-content/themes/

# Start apache on boot
RUN echo "service apache2 start" >> ~/.bashrc

我看到几个问题。 首先,除非您打算使用shell与之交互,否则容器永远不需要-t即可运行。 后台容器不需要交互式TTY界面,它们只是在后台自动运行。

其次,在您的docker文件中,我看到很多RUN语句,这些语句基本上是用于设置容器初始状态的构建时间命令,但是您没有任何CMD语句。

您需要CMD ,这是在您尝试运行容器时实际启动并在容器中启动的过程。 RUN语句在初始docker构建期间仅执行一次,然后将这些run语句的结果保存到容器映像中。 当您运行Docker容器时,其初始状态由RUN语句设置,然后CMD语句将启动容器中正在运行的进程。

因此,看起来Dockerfile中的最后一个RUN应该是CMD因为Apache服务器是您要使用以前使用所有这些RUN语句设置的容器状态运行的长时间运行的进程。

您应该做的另一件事是将许多连续的RUN语句链接成一个。 Docker为每个RUN命令创建一个单独的层,其中每个层有点像容器状态的Git提交。 因此,拥有如此多的RUN语句非常浪费,因为它占用了太多的容器层。 您可以一起执行以下这样的ot链RUN语句操作,以制作更小,更高效的容器:

RUN apt-get -y update && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install unzip wget mysql-client mysql-server apache2 libapache2-mod-php7.0 pwgen python-setuptools vim-tiny php7.0-mysql  php7.0-lda && \
    rm -fr /var/cashe/*files neeeded

我建议您阅读Docker的这份指南,该指南涵盖编写Dockerfile的最佳实践: https ://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#cmd

暂无
暂无

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

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