EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.27k stars 3.6k forks source link

Docker eosiocpp command throwing error. #4105

Closed joaoritter closed 6 years ago

joaoritter commented 6 years ago

I came across this issue, which I think is related, but I'm still having trouble. I've got my docker containers set up and running. I've successfully created keys and accounts, and successfully completed the tutorial https://github.com/EOSIO/eos/wiki/Tutorial-eosio-token-Contract and am now working on https://github.com/EOSIO/eos/wiki/Tutorial-Hello-World-Contract. I've set the following alias "alias eosiocpp='docker-compose exec keosd /opt/eosio/bin/eosiocpp'", but when I run "eosiocpp -o hello.wast hello.cpp", I get "clang-4.0: error: no such file or directory: 'hello.cpp'" I am sure I'm running from the correct directory. I'm likely misunderstanding the docs, some clarification would be great!

Thank you

ntheile commented 6 years ago

+1

I get the same error with the lastest eod-dev (v1.0.6) docker image. I have no clue what to alias besides cleos. https://developers.eos.io/eosio-nodeos/docs/docker-quickstart#section-cleos

What is the correct alias for nodeos and eosiocpp?

ntheile commented 6 years ago

I realized the file system is actually mounted from Docker to your local file system here: /tmp/eosio. So to get eosiocpp to actually compile the code, i created a contracts directory in /tmp/eosio/data/contracts then created a folder called mycontract and copied the mycontract.cpp and mycontract.hpp files over after adding my own logic (or you can generate using the skeleton command) .

Next, to generate the compiled code, I ran this docker command (notice the eosiocpp code is actually ran in docker, not your local terminal):

docker exec eosio bash -c 'cd mnt/dev/data/contracts/mycontract && eosiocpp -o mycontract.wast mycontract.cpp'

Now you can see the compiled source code on your local file system at /tmp/eosio/data/contracts

andriantolie commented 6 years ago

@ntheile is correct here. @joaoritter if you are using docker, you need to pass the contract location inside your Docker. When you call eosiocpp -o hello.wast hello.cpp, it's actually looking for hello.cpp inside the root folder of your Docker which doesn't exist. You need to map your contracts to a location inside the Docker and then pass the contract location inside your Docker to eosiocpp

luckyyang commented 6 years ago

Add the volume mapping change to your docker-compose.yml, then your docker-compose.yml would like this:

version: "3"

services:
  builder:
    build:
      context: builder
    image: eosio/builder

  nodeosd:
    container_name: nodeosd
    build:
      context: .
    image: eosio/eos-dev
    command: /opt/eosio/bin/nodeosd.sh --data-dir /opt/eosio/bin/data-dir -e
    hostname: nodeosd
    ports:
      - 8888:8888
      - 9876:9876
    expose:
      - "8888"
    volumes:
      - nodeos-data-volume:/opt/eosio/bin/data-dir
      - ../contracts:/contracts

  keosd:
    container_name: keosd
    image: eosio/eos-dev
    command: /opt/eosio/bin/keosd --wallet-dir /opt/eosio/bin/data-dir --http-server-address=127.0.0.1:8900
    hostname: keosd
    links:
      - nodeosd
    volumes:
      - keosd-data-volume:/opt/eosio/bin/data-dir
      - ../contracts:/contracts

volumes:
  nodeos-data-volume:
    external: true
  keosd-data-volume:
    external: true
  contracts:
    external: true

After the containers are running up by run docker-compose up -d, there will be a contract folder in your nodeosd and keosd container under / path, verify via these commands:

docker exec -it keosd pwd
docker exec -it keosd ls
docker exec -it keosd ls contracts

Then you will know where you are and what you have.

Every time you want to reference the contract file inside contracts folder you need to specify the path of the contract file, for example:

eosiocpp -o /contracts/hello/hello.wast /contracts/hello/hello.cpp

P.S. If you want to run eos command anywhere then use these alias (add them to your .bashrc and do not forget to change the path):

alias cleos='docker-compose -f DIR-TO-YOUR-EOS-FOLDER/Docker/docker-compose.yml exec nodeosd /opt/eosio/bin/cleos -u http://nodeosd:8888 --wallet-url http://localhost:8900'

alias eosiocpp='docker-compose -f DIR-TO-YOUR-EOS-FOLDER/eos/Docker/docker-compose.yml exec nodeosd /opt/eosio/bin/eosiocpp'
joaoritter commented 6 years ago

Perfect!

vijaytabhatt commented 6 years ago

@luckyyang i tried your docker-compose but getting error while using eosiocpp , when i run eosiocpp

alias eosiocpp='docker-compose -f /EOSBlockchain/eos/Docker/docker-compose.yml exec nodeosd /opt/eosio/bin/eosiocpp'

and run eosiocpp , i get error

OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"/opt/eosio/bin/eosiocpp\": stat /opt/eosio/bin/eosiocpp: no such file or directory": unknown

fschoell commented 6 years ago

Which docker image are you using? The eosio/eos docker image doesn't contain the eosiocpp binary. Try eosio/eos-dev instead