[英]I have made a dockerfile and I was going to run it on AWS ECS but I cant as it requires -t
Here is my docker run and the docker file is there a reason why it requires -t and isnt working on ECS thanks for any help. 这是我的docker run,并且docker文件是为什么它需要-t并且在ECS上不工作的原因,感谢您的帮助。 I dont understand what -t does so if someone could also help with that thanks.
我不明白-t会做什么,如果有人也可以提供帮助的话。
This is just a basic docker that connects to my rds and uses wordpress. 这只是一个连接到我的rds并使用wordpress的基本docker。 I dont have any plugins and shapely is the theme i'm using .
我没有任何插件,因此,这正是我使用的主题。
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
I see a couple problems. 我看到几个问题。 First of all your container should never require
-t
in order to run unless it is a temporary container that you plan to interact with using a shell. 首先,除非您打算使用shell与之交互,否则容器永远不需要
-t
即可运行。 Background containers shouldn't require an interactive TTY interface, they just run in the background autonomously. 后台容器不需要交互式TTY界面,它们只是在后台自动运行。
Second in your docker file I see a lot of RUN
statements which are basically the build time commands for setting up the initial state of the container, but you don't have any CMD
statement. 其次,在您的docker文件中,我看到很多
RUN
语句,这些语句基本上是用于设置容器初始状态的构建时间命令,但是您没有任何CMD
语句。
You need a CMD
which is the process to actually kick off and start in the container when you try to run the container. 您需要
CMD
,这是在您尝试运行容器时实际启动并在容器中启动的过程。 RUN
statements only execute once during the initial docker build, and then the results of those run statements are saved into the container image. RUN
语句在初始docker构建期间仅执行一次,然后将这些run语句的结果保存到容器映像中。 When you run a docker container it has the initial state that was setup by the RUN
statements, and then the CMD
statement kicks off a running process in the container. 当您运行Docker容器时,其初始状态由
RUN
语句设置,然后CMD
语句将启动容器中正在运行的进程。
So it looks like that last RUN
in your Dockerfile should be a CMD
since the Apache server is the long running process that you want to run with the container state that you previously setup using all those RUN
statements. 因此,看起来Dockerfile中的最后一个
RUN
应该是CMD
因为Apache服务器是您要使用以前使用所有这些RUN
语句设置的容器状态运行的长时间运行的进程。
Another thing you should do is chain many of those consecutive RUN
statements into one. 您应该做的另一件事是将许多连续的
RUN
语句链接成一个。 Docker creates a separate layer for each RUN
command, where each layer is kind of like a Git commit of the state of the container. Docker为每个
RUN
命令创建一个单独的层,其中每个层有点像容器状态的Git提交。 So it is very wasteful to have so many RUN
statements because it makes way too many container layers. 因此,拥有如此多的
RUN
语句非常浪费,因为它占用了太多的容器层。 You can do something like this ot chain RUN statements together instead to make a smaller, more efficient container: 您可以一起执行以下这样的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
I recommend reading through this guide from Docker that covers best practices for writing a Dockerfile: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#cmd 我建议您阅读Docker的这份指南,该指南涵盖编写Dockerfile的最佳实践: https ://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#cmd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.