1

I am using go-sdk for docker to create a container by code along the following lines

resp, err := cli.ContainerCreate(ctx, &container.Config{
        Image: "alpine",
        Cmd:   []string{"echo", "hello world"},
    }, nil, nil, ""/* This is container name argument*/)

I understand that the argument that takes container name, if i use the same name twice, docker engine will reject it. Also unless a stopped container is removed, the name cannot be used. My question now is that if i send such a request back to back, is the server side code thread safe or it is possible that 2 such containers may come up for a short while? Basically I looked at the rest api server handler for that and did not understand much as to what the behavior will be.

curiousengineer
  • 2,196
  • 5
  • 40
  • 59
  • 1
    The server code is thread-safe, and if you make two requests to create a container, you should always get two containers. Is that the behavior you expect? – David Maze Dec 12 '18 at 12:08
  • @DavidMaze, I might be sending create container request back to back with same name, will only one of them make it finally and all other be rejected as it is thread safe? – curiousengineer Dec 12 '18 at 17:29
  • It’s just code, and the error is just an error. What happens if you try it? – David Maze Dec 12 '18 at 18:00
  • @DavidMaze, i used docker sdk create that gets triggered via aws sqs which can get replayed at random, if docker create rejects all but one command, I can rely on it. That was the intent of asking the Q. I still have to try but from docker code I must get this `ErrNameReserved = errors.New("name is reserved")`. Am I right so far and I can rely on docker was my Q – curiousengineer Dec 12 '18 at 18:04

0 Answers0