我有来自dockerfile的映像,这是设置容器,但我需要使用docker REST API创建和启动容器.问题是我有暴露ssh端口的问题.我已经从dockerfile中删除了EXPOSE,并构建了图像.
之后,我使用这个json在/ containers/create上发出了POST请求:
{"Image":"frantiseks/apac","ExposedPorts":{"22/tcp":{}},"Memory":600000,"CpuShares":50}
Run Code Online (Sandbox Code Playgroud)
Container已成功创建,因此下一步我使用JSON 使用此POST请求 启动它/containers/$id/start:
{"PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }}
Run Code Online (Sandbox Code Playgroud)
但是在检查容器后我没有看到映射端口,所以容器没有暴露22到主机11022端口.我使用的是0.7.1版本.
有人能告诉我我做错了什么吗?谢谢
泽西岛的终点.
我想用一个端点来保护端点 ContainerRequestFilter
@Provider
@Secured
public class AuthorizationRequestFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
final SecurityContext securityContext =
requestContext.getSecurityContext();
//TODO: on logger here...
System.out.printf("Filtering %s request... AuthorizationRequestFilter\n", requestContext.getMethod());
requestContext.getHeaders().add("X-Secured-By", "Jersey >_<");
System.out.printf("SecurityContext: %s (%s).\n", securityContext, securityContext.getAuthenticationScheme());
if (securityContext == null || !securityContext.isUserInRole("privileged")) {
requestContext.abortWith(new UnauthorizedResponse().getResponse());
}
}
}
Run Code Online (Sandbox Code Playgroud)
注释@Secured:
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface Secured {}
Run Code Online (Sandbox Code Playgroud)
所以我可以这样做:
@Path("foobar")
public class FooResource {
//...
@Context
SecurityContext securityContext;
//...
@GET
@Secured
@Path(value = "foo")
@Produces(MediaType.APPLICATION_JSON) …Run Code Online (Sandbox Code Playgroud) 我正在定义一个散列,其中数组作为键,另一个数组作为其值.例如:
for_example = {[0,1] => [:a, :b, :c]}
Run Code Online (Sandbox Code Playgroud)
一切都如下所示.
my_hash = Hash.new([])
an_array_as_key = [4,2]
my_hash[an_array_as_key] #=> []
my_hash[an_array_as_key] << "the" #=> ["the"]
my_hash[an_array_as_key] << "universal" #=> ["the", "universal"]
my_hash[an_array_as_key] << "answer" #=> ["the", "universal", "answer"]
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试访问密钥:
my_hash #=> {}
my_hash.keys #=> []
my_hash.count #=> 0
my_hash.values #=> []
my_hash.fetch(an_array_as_key) # KeyError: key not found: [4, 2]
my_hash.has_key?(an_array_as_key) #=> false
Run Code Online (Sandbox Code Playgroud)
Rehash无济于事:
my_hash #=> {}
my_hash.rehash #=> {}
my_hash.keys #=> []
Run Code Online (Sandbox Code Playgroud)
但价值得以保存:
my_hash[an_array_as_key] #=> ["the", "universal", "answer"]
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?