nvim-remote-containers
nvim-remote-containers copied to clipboard
`:AttachToContainer` Results in "no image defined in the devcontainer.json"
I'm using a docker-compose.yml for in the devcontainer.json in order to ensure that a number of Docker containers start up to provide the required services for a local development environment. After a "successful" :ComposeUp I can see the running containers but when running :AttachToContainer and selecting the primary container the result is an error of no image defined in the devcontainer.json. What is also interesting is that technically there should be a devcontainer build command that builds the Devcontainer even with a docker-compose.yml file. Currently it appears that this will only "build" a Dockerfile but won't actually "build" a Devcontainer that uses a docker-composer.yml file.
I get the issue even without using docker-compose.
I had some time and messed around with the attachToContainer function. :find(containerName.name) always returned nil, meaning the function always takes the "container not created" branch:
https://github.com/jamestthompson3/nvim-remote-containers/blob/73c2cbc59b69b4026682aea6bab225831fb8eaa4/lua/docker.lua#L181-L182
The runContainer function calls getDockerArgs which hardcodes the config type as "image" when calling parseConfig, leading to the error message (at least for me, since I don't have image set in my devcontainer.json):
https://github.com/jamestthompson3/nvim-remote-containers/blob/73c2cbc59b69b4026682aea6bab225831fb8eaa4/lua/utils.lua#L66-L69
Adding a few extra arguments to the find call correctly returns a non-nil value: :find(containerName.name, 1, true). So, the attachToContainer function now correctly sees my container as created and running... and then does nothing since containerIsRunning is now truthy?
https://github.com/jamestthompson3/nvim-remote-containers/blob/73c2cbc59b69b4026682aea6bab225831fb8eaa4/lua/docker.lua#L177-L187
I'm not too familiar with Lua, so I don't have any solutions but I'm hoping this will be useful. If not, I apologize in advance!