简体   繁体   中英

How to run a Docker image inside your EC2 container?

I have an EC2 instance with the following docker image inside:

REPOSITORY       TAG      IMAGE ID
grant/docker-app hookedup b99f4ad

In my local machine I have been using docker-compose build and docker-compose up to get the servers running.

How do I get the image on the EC2 instance running?

I login to AWS with Amazon Linux AMI. I've installed docker and docker-compose on it. I can see the image but I don't know how to start it.

The docker repo is on hub.docker.com. I pulled it from there.

I have tried:

docker run -d -p 5000:5000 grant/docker-app:hookedup

which outputs some string: cdf4c4035e0...30b4d0881d635ecdac6f3

I have also tried:

docker-compose build grant/docker-app:hookedup

which outputs: Can't find a suitable configuration file in this directory or any

I have also tried

docker run --rm -p 3000:3000 grantspilsbury/docker-app:hookedup

which gives the output:

> docker-sample-app@0.1.0 start /usr/src/app
> react-scripts start

Could not find a required file.
  Name: index.html
  Searched in: /usr/src/app/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! docker-sample-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1

If I run docker ps or docker ps -a I get:

[ec2-user@ip-172...-26 ~]$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[ec2-user@ip-172...-26 ~]$ docker ps -a
CONTAINER ID        IMAGE                                       COMMAND             CREATED             STATUS                         PORTS               NAMES
0ca69ff467bc        grant/docker-app:hookedup   "npm start"         24 minutes ago      Exited (1) 24 minutes ago                          happy_archimedes
2a01050f3bb6        grant/docker-app:hookedup   "npm start"         About an hour ago   Exited (1) About an hour ago                       wonderful_rosalind

If I run docker logs 0ca69ff467bc I get the outpu:

Could not find a required file.
  Name: index.html
  Searched in: /usr/src/app/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! docker-sample-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the docker-sample-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-01-27T03_35_55_030Z-debug.log

There is a nodejs problem inside you container. Run

docker run -it --rm -p 3000:3000 --entrypoint sh grantspilsbury/docker-app:hookedup

Inspect what you have inside the container, especially /usr/src/app/public . And, perhaps, work with your developer.

In my opinion, you have an nodejs react app in the container. In the WORKDIR, there is package.json. However, the index.html could not be found indicates that not all files are copied into the image, or the app is searching in a wrong path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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