How to mount file from host to docker container on ECS - amazon-web-services

I want to mount a file from my host-EC2 to a container which is running on ECS server. Every change that happens on the file that is on the Host, should be updated on the file in container.
What I have tried is as follows:
Dockerfile:
FROM nginx
COPY conf/default.conf /etc/nginx/conf.d/default.conf
volume /etc/nginx/conf.d
RUN ln -sf conf/default.conf /etc/nginx/conf.d/
EXPOSE 80
Then pushed the image on ECR Repo and created task, added volume(source path:conf), mountpoint(/etc/nginx/conf.d) and created service to run the container. However every change that I do in the host server, dir: /conf/default.conf does not work on the container /etc/nginx/conf.d/default.conf
I know there is docker run -v but as I'm using ECR, it runs the container itself through the setup.
Any suggestion would be appreciated.

Just a suggestion: In you build system, copy the file to S3, and then in your docker container, run a script on startup that copies the latest file back from S3 and mounts it. Then you won't have to rebuild/redeploy your docker container constantly.

Related

AWS ECS Fargate - specify file path in host volumes

I am trying to create cluster in ECS Fargate with a Docker-hub image. To spin the container I have to upload a file config.json in the host so that the path could be mounted as -v /configfile/path:/etc/selenium
In local we can specify the path of json file like below.
docker run -d --name selenium -p 4444:4444 -v /E/config.json:/etc/selenium/
Whereas I am not sure where to upload the config.json file in ECS Faragte and use that path in volume.
It is not possible to do anything related to the host when using Fargate. The whole point of Fargate is that it is a "serverless" container runtime, so you have no access to the underlying server at all.
You need to look into other ways of achieving your requirement in Fargate. For example you could first copy the file to S3, and then configure the entrypoint script in your docker container to download the file from S3 before starting selenium.

Unable to deploy custom docker image to AWS ECS using Terraform

I am using terraform to build infrastructure on AWS provider. I am using ECR to push my local docker images using AWSCLI.
Now, I have a Application load balancer which would route traffic to ECS_service. I want ECS to manage my Docker Containers using Fargate. But, the docker containers are exited by saying "Essential Docker container exited".
Thats the only log printed out.
If i change the docker image to be nginx:latest(which is fetched from dockerhub). It works.
PS: My docker container is a simple node application with node:alpine as base image. Is it something related to this, i am wrong !
Can anyone provide me with some insight on what is wrong with my approach.
I get the following error in AWS Logs:
docker-standard-init-linux-go211-exec-user-process-caused-exec-format-error.
My Dockerfile
FROM node:alpine
WORKDIR /app
COPY . .
RUN npm install
# Expose a port.
EXPOSE 8080
# Run the node server.
ENTRYPOINT ["npm", "start"]
They say, its issue with the start script. I am just running this command. npm start to start the server.
It’s not your approach, your image is just not working.
Try running it locally and see the output otherwise you will need to ship the logs to Cloudwatch and see what they say

Source files of GCE instance from an image

I have created a VM instance using a docker image stored in Google container registry. The instance is working fine and I'm happy. What I am trying to figure out is where the source files are stored.
When I access the VM via SSH and navigate to usr/src/app I don't see anything. In my dockerfile I specified that directory to be used as the app directory.
WORKDIR /usr/src/app
Where can I see the source code?
The source files will be located in the location you specified within the container in question.
After you access the VM via SSH, you may run docker ps to get the list of containers running on your instance. You'll then be able to SSH into your running container via the following command:
docker exec -it <container name> /bin/bash
Once in there you should be able to see your source code in /usr/src/app.

How to check if EFS is mounted on a docker container?

I have created a task definition and mounted EFS but i'm not sure if it works..
So i wanted to verify if my EFS file system is mounted to the running container ?
How can i verify ?
One way is to add a file to the folder inside your container:
ssh into the underlying ECS EC2 instance with ssh -i "somekey.pem" ec2-user#ec2-xxxxxxxxx.eu-west-1.compute.amazonaws.com
Run docker ps to get the id of your container.
docker exec -it CONTAINERID /bin/bash to move inside the container. Inside the container create or copy a file to the EFS-folder.
Now go to the EFS console and verify that the Metered size is greater than 0 meaning your file is in EFS.
You can run a command df -h which will list your mounted volumes on linux machines.

How to share folder between host Ubuntu and already running Docker container on it?

I am using Amazon ECS, and launched the EC2 instance with ECS Linux AMI. On that EC2 instance I have multiple Docker containers each running different-different applications.
I wanted to create a folder on host, where I can add/edit anything and will get reflected to a shared folder from docker container. I have tried using following command:
docker run --name {new_container_name} -d -p 80:80 -v /{source folder}:/{destination folder}:ro {container name}
I referred to this link.
Actual Result - it will creates a new container with similar to as {container name}.
But, what I want is, I need a way with which I can create a shared folder with the current running Docker container. How can I do that?