简体   繁体   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

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.

相关问题 如何完全像在Dockerfile中一样运行Docker cmds - How do I Run Docker cmds Exactly Like in a Dockerfile 如何检查 AWS CLI --dry-run 在脚本中是否成功? - How can I check whether an AWS CLI --dry-run would have succeeded in script? 我可以从已经制作的自由式项目运行 jenkinsfile 吗? - Can I run a jenkinsfile from an already made freestyle project? 如何进入这个 dockerfile / nginx 容器? - How do I enter this dockerfile / nginx container? 如何使用 Dockerfile 设置 $PS1? - How can I set $PS1 with Dockerfile? 我尝试在bash中运行python命令时遇到问题 - I have a problem when I try to run python command in bash 我无法从“ script1.sh”运行“ script2.sh”(它们位于同一文件夹中并具有755权限) - I can't run 'script2.sh' from 'script1.sh' (they are in the same folder and have 755 permission) 如何进入服务器并运行需要bash变量和sshes到另一台服务器的bash脚本? - How do I ssh into a server and run a bash script that requires bash variables and sshes into another server? 为什么我不能使用getopt在选项和可选参数之间有空格? - Why cant I have a space between option and optional argument using getopt? 我无法获得期望脚本以“预期”方式运行远程bash脚本 - I cant get my expect script to run remote bash script as “expected”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM