Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in AWS by (19.1k points)

I have a docker file that looks like this:

FROM python:2.7

RUN pip install awscli --upgrade --user

Once the docker image is built from this docker file, I run it. But when I get into the container and try to run the AWS CLI, it can't find it, because it is not in the PATH environment variable:

$ docker exec -ti ec4934370e37 /bin/bash

[email protected]:~# aws

bash: aws: command not found

[email protected]:/# find / -name aws

/root/.local/bin/aws

[email protected]:/# /root/.local/bin/aws --version

aws-cli/1.15.81 Python/2.7.15 Linux/4.9.87-linuxkit-aufs botocore/1.10.80

[email protected]:/# env | grep PATH

PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

What is the best/easiest/least-hacky way to make sure that the AWSCLI is usable by being included in the PATH variable? Can this be done from inside the dockerfile itself?

1 Answer

0 votes
by (44.3k points)

You have two options here.

The first is to explicitly put the root user's local bin on the PATH with something like

ENV PATH=/root/.local/bin:$PATH

The second is to drop the --user argument on your pip install. By default, pip should write to /usr/local/bin which will be on your PATH already

You should read about Docker and enroll in Docker Training to grasp the concept in detail.

If you are interested to learn Python from Industry experts, you can sign up for this Python Certification Course by Intellipaat.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.7k users

Browse Categories

...