'InternalServerErrorException: Status 500: not a directory with localstack
I'm attempting to run a localstack container as part of a test in a spring boot test.
I setup a new spring boot app using the initializr, however I don't understand why I'm getting the following error when calling start:
com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: not a directory
at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:247)
at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.post(DefaultInvocationBuilder.java:124)
at org.testcontainers.shaded.com.github.dockerjava.core.exec.CreateContainerCmdExec.execute(CreateContainerCmdExec.java:37)
at org.testcontainers.shaded.com.github.dockerjava.core.exec.CreateContainerCmdExec.execute(CreateContainerCmdExec.java:13)
at org.testcontainers.shaded.com.github.dockerjava.core.exec.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:21)
at org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:35)
at org.testcontainers.shaded.com.github.dockerjava.core.command.CreateContainerCmdImpl.exec(CreateContainerCmdImpl.java:609)
at org.testcontainers.utility.ResourceReaper.start(ResourceReaper.java:117)
at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:219)
at org.testcontainers.DockerClientFactory$1.getDockerClient(DockerClientFactory.java:101)
at com.github.dockerjava.api.DockerClientDelegate.authConfig(DockerClientDelegate.java:107)
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:316)
at com.example.demo.DemoApplicationTests.contextLoads(DemoApplicationTests.java:24)
at java.base/java.util.ArrayList.forEach(Unknown Source)
at java.base/java.util.ArrayList.forEach(Unknown Source)
@ActiveProfiles("it")
@SpringBootTest
@Testcontainers
@SpringBootTest
class DemoApplicationTests {
@Container
public static LocalStackContainer localstack = new LocalStackContainer(
DockerImageName.parse("localstack/localstack")
.withTag("latest"))
.withServices(S3);
@Test
void contextLoads() {
localstack.start();
}
}
Boot version: 2.6.7
Dependancies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.914</version>
<scope>test</scope>
</dependency>
Solution 1:[1]
On which OS are you and how do you have Docker installed? This seems to happen during the preflight check, if you disable them, it will likely work for you: https://www.testcontainers.org/features/configuration/#disabling-the-startup-checks
Solution 2:[2]
Instead of ADL-hooking on the value to stream, you could overload on the stream (tagging it in some way):
int main() {
std::map<int, std::string> standback { { 42, "I'm gonna try" }, { 1729, "science" } };
streaming::tag_ostream out = std::cout;
for (auto& entry : standback)
out << entry << "\n";
}
This way, you can ADL-hook on a namespace that is under your control. You can make the tagging more generic (think auto out = streaming::tag(std::cout)).
Now, a simple implementation of that could look like
namespace streaming {
template <typename T>
struct tag : std::reference_wrapper<T> {
using std::reference_wrapper<T>::reference_wrapper;
};
using tag_ostream = tag<std::ostream>;
template <typename T1, typename T2>
static inline tag_ostream operator<<(tag_ostream os, std::pair<T1, T2> const& p) {
os.get() << "std::pair{" << p.first << ", " << p.second << "}";
return os;
}
template <typename Other>
static inline tag_ostream operator<<(tag_ostream os, Other const& o) {
os.get() << o;
return os;
}
}
See it Live On Coliru, which prints:
std::pair{42, I'm gonna try}
std::pair{1729, science}
Solution 3:[3]
I know you said that you didn't want this, but I definitely would use inheritance:
#include <iostream>
#include <utility>
#include <boost/lexical_cast.hpp>
namespace my
{
struct my_pair : std::pair<int, int> {};
std::istream& operator>>(std::istream& stream, my_pair& pair)
{
stream >> pair.first;
stream >> std::skipws;
stream >> pair.second;
return stream;
}
}
int main()
{
my::my_pair p = boost::lexical_cast<my::my_pair>("10 10");
std::cout << p.first << " " << p.second << std::endl;
}
(live demo)
Your my::my_pair literally is-a std::pair<int, int>; you just need it to be a distinct type in your own namespace. This is what inheritance is for.
I'm just leaving this here to show how easy it is to do and explain why I think you should do it.
Solution 4:[4]
Doing so, would result in undefined behavior, because I would be adding functions to the namespace std.
I would like to avoid inheritance, as in struct my_pair : std::pair.
I wanted to say "inheritance", but you dismiss it ...
You could use encapsulation, simply adding another strong type over std::pair<int,int> (but in such a trivial case, you may be better off with the custom structure - your commented code):
struct my_pair
{
std::pair<int,int> value;
// TODO: add any access interface here
};
std::istream& operator>>(std::istream& stream, my_pair& pair)
{
stream >> pair.value.first;
stream >> std::skipws;
stream >> pair.value.second;
return stream;
}
Infact, you probably should do this, because std::pair is more of a building block, not something that should be used to represent semantic information (and not something that should be dirrectly printable to a stream).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kevin Wittek |
| Solution 2 | |
| Solution 3 | Lightness Races in Orbit |
| Solution 4 |
