Few questions about Docker and Jenkins

Discussion in 'Programming/Scripts' started by Piotrek, Jul 11, 2019.

  1. Piotrek

    Piotrek New Member

    I have few questions:
    1. What is the difference between docker exec/docker-compose exec and docker run/docker-compose run? Honestly I have a problem with understanding but I found out, for example that below will work (I run commands in Jenkinsfile - I attach the file):
    Code:
    sh "docker-compose up --no-start"
    sh "docker-compose run -e RAILS_ENV=test app bundle exec rake db:setup"
    sh "docker-compose run -e RAILS_ENV=test app bundle exec rake rspec spec"
    
    but this won't:
    Code:
    sh "docker-compose up"
    sh "docker-compose exec -T -e RAILS_ENV=test app bundle exec rake db:setup"
    sh "docker-compose exec -T -e RAILS_ENV=test app bundle exec rake rspec spec"
    
    2. Why docker-compose run creates something like main container "cordeo-api_test-docker_app_1" but later next two "cordeo-api_test-docker_app_run_1" (related with first docker-compose run) and "cordeo-api_test-docker_app_run_2" (related with second docker-compose run). It looks like below:
    Code:
    jenkins@jenkins:~/workspace/cordeo-api_test-docker$ docker-compose ps
    WARNING: The BRANCH_NAME variable is not set. Defaulting to a blank string.
                  Name                             Command                  State        Ports
    --------------------------------------------------------------------------------------------
    cordeo-api_test-docker_app_1        /app/lib/docker-entrypoint.sh    Exit 0
    cordeo-api_test-docker_app_run_2    /app/lib/docker-entrypoint ...   Up             3000/tcp
    cordeo-api_test-docker_postgres_1   docker-entrypoint.sh postgres    Up (healthy)   5432/tcp
    cordeo-api_test-docker_redis_1      docker-entrypoint.sh redis ...   Up             6379/tcp
    
    Do these commands run "rake db:setup" and "rake rspec spec" on this same container?
    3. How create network with static addressation which will be used by containers created by docker-compose. I have added at the end of docker-compose.yml (I attach the file):
    Code:
    # networks:
    # app_net:
    # ipv4_address: 172.18.0.1
    #networks:
    # app_net:
    # ipam:
    # driver: default
    # config:
    # - subnet: "172.18.0.0/24"
    
    I have added the files as .txt. Their real extensions are earlier in name string.
     

    Attached Files:

Share This Page