Sudo: command not found


#1

I’m trying to configure the hosts file as per the doc: https://circleci.com/docs/2.0/configuration-reference/#example

echo 127.0.0.1 www.localhost.local | sudo tee -a /etc/hosts

But I’m getting “/bin/bash: sudo: command not found”

If I remove the sudo then I get a permission error. Any idea what’s up?


#2

What container are you using?


#3

Sorry for the late reply. Here’s the job description:

jobs:
  build:
    working_directory: ~/app
    docker:
      - image: node:8.1.4
      - image: circleci/ruby:2.2.7
      - image: redis:3.0.7

    steps:
      - checkout
      - run: echo 127.0.0.1 www.localhost.local | sudo tee -a /etc/hosts
      - run: echo 127.0.0.1 api.localhost.local | sudo tee -a /etc/hosts
      - run:
          name: install-npm
          command: npm install -g npm
      - run:
          name: install-phantom
          command: sudo curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
      - run:
          name: setup-db
          command: bundle exec rake db:drop db:create db:migrate

#4

You’re using the official Node Docker image which is based on a Docker image called buildpack-deps (specifically, the Debian Jessie version). The buildpack Docker image does not have sudo installed, which is not surprising since most Docker images run as root by default until told to switch to another user and group.

Since the Node Docker image doesn’t switch the user or group (though it does create both), you’re actually still running as root throughout the execution of the steps. In other words, you should be able to remove sudo and it will work just fine.

If you would like to use sudo, you’ll either need a separate run step or create a Docker image on top of the Node image that contains sudo.

  - run: apt-get install -y sudo

or

FROM node:8.1.4
RUN apt-get install -y sudo
CMD ["node"]

As an aside, based on your configuration file above, it looks like you’re trying to use both Node and Ruby in the steps. I believe you’ll run into an issue because your commands are going to execute inside the container based on Node; the Ruby and Redis images will be loaded separately. What you probably want to do instead is create a custom image that includes both Node and Ruby. That will allow you to call both Ruby and Node commands.


#5

Thanks for the reply David! I’ll try installing the package. Without sudo it gave a permission error.

Do you have doc on creating custom images?


#6

@blarralde here it is: https://circleci.com/docs/2.0/custom-images/


#7

Thank you!


#8

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.