3

I am new to Docker and I am trying to run Selenium Grid tests on Docker. For this purpose, I created a docker compose file and executed below command

docker-compose -f docker-compose.yaml up

Everything worked fine but after a few hours I restarted host machine and executed above command again. This time I get below error

ERROR: for selenium-hub  Cannot create container for service selenium-hub: Conflict. The container name "/selenium-hub" is already in use by container "some-hash". You have to remove (or rename) that container to be able to reuse that name.

I tried docker-compose -f docker-compose.yaml run selenium-hub but this command does not start selenium nodes. So my questions are -

  • Do I need to remove the container everytime before I run the docker compose again?
  • Is there any way I can use docker-compose like file, so that
    everytime I restart docker, I can just run the file to start all containers together?

Below the Docker-Compose I used

version: "3"
services:
  selenium-hub:
    image: selenium/hub:3.141.59-20200525
    container_name: selenium-hub
    ports:
      - "4444:4444"

  chrome:
    image: selenium/node-chrome:3.141.59-20200525
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444

  firefox:
    image: selenium/node-firefox:3.141.59-20200525
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444

  opera:
    image: selenium/node-opera:3.141.59-20200525
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
Miracle
  • 81
  • 6

2 Answers2

3

There are possible ways

  1. docker system prune will clean up the cache and remove the dangling intermediate container and delete containers name that not actively running. This command have to be used carefully
  2. docker container prune will delete only dead/stop containers and will free up names
  3. docker rm -v $(docker ps -aq -f 'status=exited')
  4. docker rmi $(docker images -aq -f 'dangling=true')
  5. docker-compose rm --force emoves one-off containers created by docker-compose up or docker-compose run
-1

Just use docker-compose up command to start the already created containers.

aryanveer
  • 628
  • 1
  • 6
  • 17